INSERT INTO user (user, pass) VALUES ('张二毛', 'PA55W0RD')
'引用microsoft actionX data objects 2.* library '一个 用户控件:text1 2个密码控件:text2、text3 Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim sql As String Dim i As Integer cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=data;Data Source=." sql = "select * from user where user='" & text1.text & "'" cn.Execute sql, i if i=0 then sql = "INSERT INTO user (user, pass) VALUES ('" & text1.text & "','" & text2.text & "')" rs.Open sql, cn, adOpenKeyset, adLockOptimistic else msgbox "用户名已存在,请重新注册" end if rs.close cn.close
然后写如SQL里
'一个 用户控件:text1 2个密码控件:text2、text3
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim i As Integer
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=data;Data Source=."
sql = "select * from user where user='" & text1.text & "'"
cn.Execute sql, i
if i=0 then
sql = "INSERT INTO user (user, pass) VALUES ('" & text1.text & "','" & text2.text & "')"
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
else
msgbox "用户名已存在,请重新注册"
end if
rs.close
cn.close