这是为什么“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中”
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim t_username As String
Dim t_password As String
t_username = Me.txtUserName.Text
t_password = Me.txtPassword.Text
Dim msgt As String
msgt = " "
If Trim(txtUserName.Text = " ") Then
msgt = "请输入用户名 "
ElseIf Trim(txtPassword.Text = " ") Then
msgt = "请输入密码 "
End If
If Not msgt = " " Then
MsgBox(msgt)
Exit Sub
End If
Dim str As String = "uid=sa;pwd=;database=Northwind;server=127.0.0.1;Provider= 'SQLOLEDB.1 ' "
Dim conn1 As New OleDbConnection(str)
Dim selectName As OleDb.OleDbCommand = New OleDbCommand( "select * from Customers where CustomerID= ' " & t_username & " ' and CompanyName= ' " & t_password & " ' ", conn1)
conn1.Open()//!!!报错停在这里!
Dim result As OleDb.OleDbDataReader
result = selectName.ExecuteReader()
result.Read()
If result.HasRows Then
MsgBox( "登陆成功 ")
Else
MsgBox( "用户名或密码错误 ")
End If
conn1.Close()
End Sub
这是什么原因!???
------解决方案--------------------
检查一下数据库连接是否正确
[解决办法]
' '操作数据库
Dim DbConnString As String = "PROVIDER=SQLOLEDB.1;DATASOURCE=127.0.0.1;UID=test;PWD=testdb;DATABASE=Northwind "
Dim SqlString As String= "select * from Customers where .... "
Using connection As New OleDb.OleDbConnection(DbConnString)
Dim command As New OleDb.OleDbCommand(SQLString, connection)
connection.Open()
Dim reader As OleDb.OleDbDataReader = command.ExecuteReader()
If reader.HasRows Then
MsgBox( "登陆成功 ")
Else
MsgBox( "用户名或密码错误 ")
End If
reader.Close()
End Using