首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

有关数据类型的有关问题

2012-03-22 
有关数据类型的问题?我的备注是采用ntext类型的当进行插入操作的时候,我在备注写2222是可以的,可是当我进

有关数据类型的问题?
我的备注是采用ntext类型的

当进行插入操作的时候,我在备注写2222是可以的,可是当我进行修改这条记录时,(其实备注的2222没被修改),它就提示我整数型不可以写入ntext型
我不明白为何连插入都成功,可是修改反而提示出错??
附上我的代码:
//添加按钮的代码
procedure Tryxxfrm.Button2Click(Sender: TObject);
var
  YGBH,YGXM,BMBH,ZWBH,LXDH,DZYJ,BZ ,temp1,temp2,sqltext:string;
begin
  temp1:=combobox2.text;
  temp2:=combobox3.text;
 
  if((edit2.Text='')or(edit3.Text='')or(edit4.Text='')or(edit5.text='')or(combobox2.Text='')or(combobox3.text='') )then
  showmessage('请填写完整的信息')
  else
  begin
  with datamodulemis.adoquerybm do
  begin
  close;
  sql.clear;
  sql.Add('select bmbh from bm where bmm='+''''+temp1+'''');
  open;
  BMBH:=fieldbyname('bmbh').asstring;

  end;
  with datamodulemis.adoqueryzw do
  begin
  close;
  sql.clear;
  sql.Add('select zwbh from zw where zwmc='+''''+temp2+'''');
  open;
  ZWBH:=fieldbyname('zwbh').asstring;

  end;
  YGBH:=edit2.Text;
  YGXM:=edit3.Text;
  LXDH:=edit4.Text;
  DZYJ:=edit5.Text;
  BZ:=memo1.Text;
  sqltext:='Insert yg values('''+YGBH+''','''+YGXM+''','''+BMBH+''','''+ZWBH+''','''+LXDH+''','''+DZYJ+''','''+BZ+''')';
  with datamodulemis.adoqueryyg do
  begin
  close;
  sql.Clear;
  sql.add(sqltext);
  execsql;
  showmessage('插入成功');
  end; 



  end;
//修改按钮的代码:
procedure Tryxxfrm.Button5Click(Sender: TObject);
  var
  YGBH,YGXM,BMBH,ZWBH,LXDH,DZYJ,BZ ,temp1,temp2,sqltext:string;
begin
  temp1:=combobox2.text;
  temp2:=combobox3.text;
 
  if((edit2.Text='')or(edit3.Text='')or(edit4.Text='')or(edit5.text='')or(combobox2.Text='')or(combobox3.text='') )then
  showmessage('请填写完整的信息')
  else
  begin
  with datamodulemis.adoquerybm do
  begin
  close;
  sql.clear;
  sql.Add('select bmbh from bm where bmm='+''''+temp1+'''');
  open;
  BMBH:=fieldbyname('bmbh').asstring;

  end;
  with datamodulemis.adoqueryzw do
  begin
  close;
  sql.clear;
  sql.Add('select zwbh from zw where zwmc='+''''+temp2+'''');
  open;
  ZWBH:=fieldbyname('zwbh').asstring;

  end;
  YGBH:=edit2.Text;
  YGXM:=edit3.Text;
  LXDH:=edit4.Text;
  DZYJ:=edit5.Text;
  BZ:=memo1.Text;
  sqltext:='update yg set ygxm ='+ YGXM+',lxdh='+LXDH+',dzyj='+DZYJ+',zwbh= '+ZWBH+',bmbh='+BMBH+',bz='+BZ+'where ygbh='+YGBH;
  with datamodulemis.adoqueryyg do
  begin
  close;
  sql.Clear;
  sql.add(sqltext);
  execsql;
  showmessage('修改成功');
  end; 


------解决方案--------------------


Delphi(Pascal) code
sqltext:= 'update yg set ygxm = '+ QuotedStr(YGXM)+ ',lxdh= '+QuotedStr(LXDH)+ ',dzyj= '+QuotedStr(DZYJ)+ ',zwbh=  '+QuotedStr(ZWBH)+ ',bmbh= '+QuotedStr(BMBH)+ ',bz= '+QuotedStr(BZ)+ 'where ygbh= '+QuotedStr(YGBH);
[解决办法]
sqltext:= 'update yg set ygxm = '+ QuotedStr(YGXM)+ ',lxdh= '+QuotedStr(LXDH)+ ',dzyj= '+QuotedStr(DZYJ)+ ',bmbh= '+QuotedStr(BMBH)+ ',bz= '+QuotedStr(BZ)+ 'where ygbh= '+QuotedStr(YGBH)+ ' and zwbh='+QuotedStr(Zwbh);

热点排行