delphi创建数据库和 表单(18分)

  • 主题发起人 主题发起人 hfutzhu
  • 开始时间 开始时间
H

hfutzhu

Unregistered / Unconfirmed
GUEST, unregistred user!
要在delphi里动态创建数据库和数据库表,如果数据库中已经有了这张表,如何进行判断,已经存在!<br>如:要创建hfut1这张表 该怎么在delphi里写,如果已经有了hfut1了 在delphi如何处理
 
以delphi的方式执行SQL语句啊
 
procedure TForm1.FormShow(Sender: TObject);<br>&nbsp; &nbsp; var<br>&nbsp; &nbsp; &nbsp; CreateAccess:OleVariant;<br>begin<br>&nbsp; &nbsp;if FileExists('new.mdb') then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;with Dm.ADOQ1 do<br>&nbsp; &nbsp; &nbsp; CreateAccess:=CreateOleObject('ADOX.Catalog');<br>&nbsp; &nbsp; &nbsp; CreateAccess.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=./new.mdb');<br>&nbsp;// &nbsp; close;<br>&nbsp; &nbsp; &nbsp; Dm.ADOQ1.SQL.Clear;<br>&nbsp; &nbsp; &nbsp; Dm.ADOQ1.SQL.add('create table 表名( 字段1 identity(1,1)primary key,字段2 char(200),字段3 char(200))');<br>&nbsp; &nbsp; &nbsp; Dm.ADOQ1.execsql; <br><br>&nbsp; &nbsp;end;
 
adoquery1.close; &nbsp; <br>&nbsp; adoquery1.sql.clear; &nbsp; <br>&nbsp; adoquery1.sql.add(sp_tables &nbsp; 你要查的表名); &nbsp; <br>&nbsp; adoquery1.open; &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; if &nbsp; adoquery1.recordcount&gt;1 &nbsp; then &nbsp; <br>&nbsp; &nbsp; &nbsp; //说明有这个表 &nbsp; <br>&nbsp; else &nbsp; <br>&nbsp; &nbsp; &nbsp; //说明没有这个表<br><br><br>已经搞定了,谢谢大家了!
 
后退
顶部