主题:VB.NET--System.Data.OleDb.OleDbException类型的异常
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlString As String
sqlString = "select 用户名,密码 from user where 用户名=' " & TextBox1.Text & " '"
Dim objectdsDataSet As New DataSet
Dim oleconn As New OleDb.OleDbConnection(conn)
Dim adapter As New OleDb.OleDbDataAdapter
adapter.TableMappings.Add("table", "user")
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, oleconn)
cmd.CommandType = CommandType.Text
adapter.SelectCommand = cmd
If oleconn.State <> ConnectionState.Open Then
oleconn.Open() [color=800000][size=5]//出错的地方[/size][/color]
End If
cmd.ExecuteNonQuery()
If oleconn.State <> ConnectionState.Closed Then
oleconn.Close()
End If
adapter.Fill(objectdsDataSet)
If objectdsDataSet.Tables("user").Rows.Count = 0 Then
MsgBox("您输入的用户名或密码有误,请重新输入!", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
If objectdsDataSet.Tables("user").Rows(0)("密码").ToString = TextBox2.Text Then
userName = Trim(TextBox1.Text)
userPwd = Trim(TextBox2.Text)
Dim f1 As New Form1
f1.Show()
f1.MenuItem3.Enabled = True
f1.MenuItem4.Enabled = True
Me.Finalize()
Else
MsgBox("请输入的用户名或密码有误,请重新输入!", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
可是出错,希望高手指教,谢了!!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlString As String
sqlString = "select 用户名,密码 from user where 用户名=' " & TextBox1.Text & " '"
Dim objectdsDataSet As New DataSet
Dim oleconn As New OleDb.OleDbConnection(conn)
Dim adapter As New OleDb.OleDbDataAdapter
adapter.TableMappings.Add("table", "user")
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, oleconn)
cmd.CommandType = CommandType.Text
adapter.SelectCommand = cmd
If oleconn.State <> ConnectionState.Open Then
oleconn.Open() [color=800000][size=5]//出错的地方[/size][/color]
End If
cmd.ExecuteNonQuery()
If oleconn.State <> ConnectionState.Closed Then
oleconn.Close()
End If
adapter.Fill(objectdsDataSet)
If objectdsDataSet.Tables("user").Rows.Count = 0 Then
MsgBox("您输入的用户名或密码有误,请重新输入!", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
If objectdsDataSet.Tables("user").Rows(0)("密码").ToString = TextBox2.Text Then
userName = Trim(TextBox1.Text)
userPwd = Trim(TextBox2.Text)
Dim f1 As New Form1
f1.Show()
f1.MenuItem3.Enabled = True
f1.MenuItem4.Enabled = True
Me.Finalize()
Else
MsgBox("请输入的用户名或密码有误,请重新输入!", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
可是出错,希望高手指教,谢了!!