vb中如何只用一个按钮事件将数据添加到数据库中

来源:百度知道 编辑:UC知道 时间:2024/06/05 15:01:38
例如:有一个文本框和一个按钮,在文本框有内容的情况下,只点一下按钮就将文本框中的数据添加到数据库中,具有和下面一样的功能:
类似于两个按钮的情况:先点按钮一执行data1.recordset.addnew,将文本框中填入信息之后,再点击按钮二执行data1.recordset.update将文本框中的信息添加到数据库中。
我该如何写哪一个按钮的单击事件???十分紧急!!!

if command1.caption="准备添加" then
data1.recordset.addnew
command1.caption="确认添加"
else
if text1<> "" then
data1.recordset.update
command1.caption="准备添加"
else
msgbox "请输入文本"
text1=.setforce
end if
end if

private sub command1_click()
dim cn as adodb.connection
dim sql as string
set cn=new adodb.connection
cn.open "数据库连接套接字"
sql="insert into 表名(字段名) values('"+text1.text+"')"
if len(text1.text)>0 then
cn.execute sql
end if
set cn=nothing
end sub

data1.recordset.update也些在前一个按钮事件里啊