vb sql数据库问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 20:46:13
在做一个添加用户的界面要连接到sql数据库yonghu这张表中
代码如下:
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then
MsgBox "用户名不能为空!", vbExclamation + vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "密码不能为空!", vbExclamation + vbOKOnly, "警告"
Text2.SetFocus
Exit Sub
End If
If Trim(Text3.Text) = "" Then
MsgBox "确认密码不能为空!", vbExclamation + vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If
If Trim(Text2.Text) <> Trim(Text3.Text) Then
MsgBox "确认密码不正确!", vbExclamation + vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If

Dim mrc As ADODB.Recordset
txtsql = "select * from yonghu where username='" & Trim(Text1.Text) & "'"
Set mrc = ExecuteSQL(txtsql)
If mrc.EOF = False Then
MsgBox " 已存在该用户

ADODB.Recordset这个东西你要引用.vb6你不应用,VB6不知道ADODB是什么东西的

ExecuteSQL 这个函数没有定义.所以:
先引用ADO2.7,然后写:
dim cn as new adodb.connect
dim mrc as new adodb.recordset
Set mrc = cn.execute(txtsql)