vb简单插入数据库问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 05:22:37
vb+access 在表中插入一条信息
一共9个text 第一个text为编号 ,先用来验证数据库中是否有该编号信息,没有就插入新信息,应当怎么写? 菜鸟 谢谢

Set rs = New ADODB.Recordset
Set conn = New ADODB.Connection
conn.open connstring
sql = "select * from 表名 where 编号='" & text1.Text & "'"
rs.open sql, conn, 3, 3
If rs.EOF Then
rs.addnew
rs("表里的列名1") = text1.Text
rs("表里的列名2") = text2.Text
rs("表里的列名3") = text3.Text
rs("表里的列名4") = text4.Text
rs("表里的列名5") = text5.Text
rs("表里的列名6") = text6.Text
rs("表里的列名7") = text7.Text
rs("表里的列名8") = text8.Text
rs("表里的列名9") = text9.Text
rs.Update
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
其中的connstring就是连接数据库的字符串,我不知道你连接什么数据库,自己添。

sqlstr="select * from "表名" where 编号= text1.text
conn.execute sqlstr
if rs.eof then
rs.addnew
rs.field()=""
end if

Set rs = New ADODB.Recordset
Set co