DAO方法如下:Dim 数据库 As Database Dim 数据表 As TableDef Dim 字段 As Field Dim 索引 As Index Dim 记录集 As Recordset Dim 记录集2 As RecordsetPrivate Sub 添加_Click() 记录集.AddNew Call 显示空字段 End SubPrivate Sub 显示空字段() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" End SubPrivate Sub 更新_Click() If MsgBox("是否更新?", 17) <> 1 Then Exit Sub 记录集.Edit 记录集.AddNew 记录集("日期") = CDate(Text1.Text) 记录集("数量") = CInt(Text4.Text) 记录集("价格") = CDbl(Text5.Text) 记录集("承印人") = Text2.Text 记录集("种类") = Text3.Text 记录集.Update End Sub
dim conn as new adodb.connectiondim rs as new adodb.recordsetconn.open "provider=microsfot.jet.oledb.4.0;data source=" & app.path("db1.mdb")rs.open "select f1,f2,f3,f4 from t1",conn,1,3rs.addnewrs(0)="f1"rs(1)="f2"rs(2)="f3"rs(3)="f4" rs.update
也可以用insert into语句conn.execute "insert into t1(f1,f2,f3,f4) values ('f1','f2','f3','f4')"
Dim 数据表 As TableDef
Dim 字段 As Field
Dim 索引 As Index
Dim 记录集 As Recordset
Dim 记录集2 As RecordsetPrivate Sub 添加_Click()
记录集.AddNew
Call 显示空字段
End SubPrivate Sub 显示空字段()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End SubPrivate Sub 更新_Click()
If MsgBox("是否更新?", 17) <> 1 Then Exit Sub
记录集.Edit
记录集.AddNew
记录集("日期") = CDate(Text1.Text)
记录集("数量") = CInt(Text4.Text)
记录集("价格") = CDbl(Text5.Text)
记录集("承印人") = Text2.Text
记录集("种类") = Text3.Text
记录集.Update
End Sub
rs.update
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"
数据库为TE,有没有更好的方法,我的数据库里的字段太多了,有21个。
如果用楼上的办法好麻烦的。
我想点击“添加记录“时,就很方便的添加记录。
有不有更好的办法?