我连接的是SQL数据库,用ADO
错误发生在“rs.addnew
就是创建一个新用户
Private conn As Connection
Private rs As Recordset
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.CursorLocation = adUseClient
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=sa;Initial Catalog=example"
conn.Open
End Sub
Private Sub com1_Click()
Dim sql As String
If Trim(passt.Text) <> Trim(passt2.Text) Then
MsgBox "您输入的密码不一致"
Else
sql = "select * from manager"
rs.Open sql, conn, adOpenDynamic
While (rs.EOF = False)
If Trim(usert.Text) = "" Then
MsgBox "用户名不能为空"
ElseIf (rs.Fields(0) = Trim(usert.Text)) Then
MsgBox "该用户已经存在"
Else
rs.AddNew
rs.Fields(0) = Trim(usert.Text)
rs.Fields(1) = Trim(passt.Text)
rs.Update
End If
rs.MoveNext
Wend
End If
End Sub