如果没有新表,如何从一个表复制到新表,请给出正确的代码(100分)

  • 主题发起人 主题发起人 fscdc4
  • 开始时间 开始时间
F

fscdc4

Unregistered / Unconfirmed
GUEST, unregistred user!
如果没有表newfile,则从fromfile表复制到newfile,我的代码如下:<br>procedure Tgrobalsform.tonewtable1(fromfile:string;newfile:string); &nbsp; //保存code<br>var sqlstr:string;<br>begin<br>&nbsp; &nbsp;newfileADOquery.close;<br>&nbsp; &nbsp;newfileADOquery.sql.clear;<br>&nbsp; &nbsp;sqlstr:='IF Not Exists(';<br>&nbsp; &nbsp;sqlstr:=sqlstr+'SELECT * FROM syscolumns WHERE (id = OBJECT_ID(N'+quotedstr(newfile)+')) ';<br>&nbsp; &nbsp;sqlstr:=sqlstr+' BEGIN &nbsp;';<br>&nbsp; &nbsp;sqlstr:=sqlstr+'select * into '+newfile+' from '+fromfile;<br>&nbsp; &nbsp;sqlstr:=sqlstr+' END ';<br>&nbsp; &nbsp;newfileADOquery.sql.add(sqlstr);<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;newfileADOquery.execsql;<br>&nbsp; &nbsp;except<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;newfileADOquery.close;<br>end;<br>编译出错,begin 附近有语法错误,请给出正确的代码
 
你用的数据库是什么数据库?将你代码里面的sql拿到数据库中直接执行看看。
 
这样就可以了。<br>我还以为运行错误,原来是编译错误,那不是很简单吗,看错误提示就行了。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; sqlstr:string;<br>&nbsp; newfile,fromfile: string;//新加的两个变量的声明<br>begin<br>&nbsp; &nbsp;newfileADOquery.close;<br>&nbsp; &nbsp;newfileADOquery.sql.clear;<br>&nbsp; &nbsp;sqlstr:='IF Not Exists(';<br>&nbsp; &nbsp;sqlstr:=sqlstr+'SELECT * FROM syscolumns WHERE (id = OBJECT_ID(N'+quotedstr(newfile)+')) ';<br>&nbsp; &nbsp;sqlstr:=sqlstr+' BEGIN &nbsp;';<br>&nbsp; &nbsp;sqlstr:=sqlstr+'select * into '+newfile+' from '+fromfile;<br>&nbsp; &nbsp;sqlstr:=sqlstr+' END ';<br>&nbsp; &nbsp;newfileADOquery.sql.add(sqlstr);<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;newfileADOquery.execsql;<br>&nbsp; &nbsp;except<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;newfileADOquery.close;<br>end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部