VB里怎么把工程和数据库连接?

来源:百度知道 编辑:UC知道 时间:2024/05/14 05:08:56
我弄了个登陆框和数据库里的一个用户表连接,可是编写代码的时候出错,高手帮我看看!!
Dim sql As String

Public Function exesql(ByVal sql As String) As ADODB.Recordset
sql = Trim$(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "DSN=shiyan1;UID=;PWD="
conn.Open
Set rst.ActiveConnection = conn
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open sql <---这句出错!!
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
Sub main()
pass.Show vbModal
End Sub
Private Sub Command1_Click()
Dim mrc As ADODB.Recordset
txtsql = "select * from yonghu where username'" & Trim$(Text1.Text) & "'" & " And userpassword = " & Trim$(Text2.Text) + " '"
Set mrc = exesql(txtsql)
If mrc.RecordCount = 0 Then
message = MsgBox("用户名或密码错误!", 0, "消息提示")
Else
u

select * from yonghu where username='" & Trim$(Text1.Text) & "' And userpassword ='" & Trim$(Text2.Text) & "'"
这么写吧?

你那个用户和密码如果数据库里没有设,这里也不要写

\\\\\\\\\\\\\\\\\\\\\13:44add

怎么是text.text 我看你程序里面是text1阿