利用oledbconnection连接sql数据库的问题
jiez 2011-02-26 10:55:46 如题,做了一个简单的登录界面,输入正确的用户名和密码,明明数据库中存在这样的用户名和密码,可是还是进入“ MsgBox("用户名不存在或者密码错误", 0 + 48, "提示")”,经检测好像是没有查出数据来,怎么回事呢?
另外,该定义的都定义了,没有出现编译错误。
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("请输入用户名", MsgBoxStyle.Information, "警告")
Exit Sub
End If
If TextBox2.Text = "" Then
MsgBox("请输入密码", MsgBoxStyle.Information, "警告")
Exit Sub
End If
Dim myconnection As OleDb.OleDbConnection
Dim strconnet As String = "Provider=SQLOLEDB;Data Source=(Local);Initial Catalog=chapter1;user id=sa;password=;"
myconnection = New System.Data.OleDb.OleDbConnection(strconnet)
myconnection.Open()
Dim str As String = "select * from aa where name=' & TextBox1.Text& ' and pwd=' & TextBox2.Text& '"
mycommand = New OleDbCommand(str, myconnection)
mydatareader = mycommand.ExecuteReader
Dim a As String = mydatareader.GetString(0)
TextBox3.Text = a
If mydatareader.Read = False Then
MsgBox("用户名不存在或者密码错误", 0 + 48, "提示")
Else
Me.Hide()
Dim f2 As New Form2
f2.Show()
End If
mydatareader.Close()
myconnection.Close()
End Sub