我做了个试验。想把text中的内容通过Command1_Click()事件添加进
adodc1所连接的数据库中我把代码写成了
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("VS") = Text1.Text
Adodc1.Recordset.Update
End Sub
但总是显示
实时错误'91':
对象变量或with块变量未设置调试的时候错误总是指向Adodc1.Recordset.AddNew这段请问一下如果要吧text里面的内容写进adodc所连接的数据库指定列中,代码需要怎么改呢?
adodc1所连接的数据库中我把代码写成了
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("VS") = Text1.Text
Adodc1.Recordset.Update
End Sub
但总是显示
实时错误'91':
对象变量或with块变量未设置调试的时候错误总是指向Adodc1.Recordset.AddNew这段请问一下如果要吧text里面的内容写进adodc所连接的数据库指定列中,代码需要怎么改呢?
Adodc1.Recordset.ActiveConnection.Execute ("insert into 表名 (VS) values('" & text1.text & "')")
adodc.refresh
end sub
Private Sub Command1_Click()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False" '连接数据库
Adodc1.CommandType = adCmdTable '命令类型是表
Adodc1.RecordSource = "bjsj" 'bjsj是表名
Adodc1.Refresh '打开数据库 Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("jkd") = Text1.Text
Adodc1.Recordset.Update
End Sub
也可以这么写
Private Sub Command1_Click()
cnn.ConnectionString = getConnString
cnn.Openend
sql = "insert into 表名 (VS) values ...."
cnn.Execute sql
cnn.close
end sub