主题:请问出现"未将对象引用设置到对象的实例"是什么原因呢????
这是一个登陆窗口的代码,画线处就是出现错误提示的地方:
Public Const CONN = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=D:\图书资料管理系统.mdb"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQLString As String
SQLString = "select * from 用户表 WHERE 用户名='" & TextBox2.Text & "'"
'SQL查询语句
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() '打开数据连接
End If
cmd.ExecuteNonQuery()
If oleconn.State <> ConnectionState.Closed Then
oleconn.Close() '关闭数据库连接
End If
adapter.Fill(ObjectdsDataSet)
[u] If ObjectdsDataSet.Tables("User").Rows.Count = 0 [/u]Then '判断用户是否存在
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
[u]If ObjectdsDataSet.Tables("User").Rows(0)("密码").ToString = TextBox1.Text Then[/u] '判断用户密码是否正确
ManagerName = Trim(TextBox2.Text) '记录当前用户名
Password = Trim(TextBox1.Text) '记录当前的密码
AddLog("登陆系统") '写日志
Dim form3 As New Form3
Me.Hide()
form3.Show()
'打开主窗体,并隐藏登录窗体
Else
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
End Sub
Public Const CONN = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=D:\图书资料管理系统.mdb"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQLString As String
SQLString = "select * from 用户表 WHERE 用户名='" & TextBox2.Text & "'"
'SQL查询语句
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() '打开数据连接
End If
cmd.ExecuteNonQuery()
If oleconn.State <> ConnectionState.Closed Then
oleconn.Close() '关闭数据库连接
End If
adapter.Fill(ObjectdsDataSet)
[u] If ObjectdsDataSet.Tables("User").Rows.Count = 0 [/u]Then '判断用户是否存在
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
[u]If ObjectdsDataSet.Tables("User").Rows(0)("密码").ToString = TextBox1.Text Then[/u] '判断用户密码是否正确
ManagerName = Trim(TextBox2.Text) '记录当前用户名
Password = Trim(TextBox1.Text) '记录当前的密码
AddLog("登陆系统") '写日志
Dim form3 As New Form3
Me.Hide()
form3.Show()
'打开主窗体,并隐藏登录窗体
Else
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
End Sub