主题:[原创]如何从数据集里面读出数据!!!!!!!
Dim MyDataSet As New DataSet
Dim Conn As String = "provider=Microsoft.jet.oledb.4.0;data source =login.mdb"
Dim MyConn As New OleDb.OleDbConnection
Dim MyDAO As New OleDb.OleDbDataAdapter
MyDAO.TableMappings.Add("Table", "user")
Dim MyCommand As OleDb.OleDbCommand
MyCommand = New OleDb.OleDbCommand("SELECT * FROM userID WHERE 用户名='" & TxtUserName.Text & "'", MyConn)
MyCommand.CommandType = CommandType.Text
MyDAO.SelectCommand = MyCommand
If MyConn.State <> ConnectionState.Open Then
MyConn.ConnectionString = Conn
MyConn.Open()
End If
MyCommand.ExecuteNonQuery()
If MyConn.State <> ConnectionState.Closed Then
MyConn.Close()
End If
MyDAO.Fill(MyDataSet)
If MyDataSet.Tables("user").Rows.Count = 0 Then
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
If MyDataSet.Tables("User").Rows(0)("密码").ToString = TxtUserPassword.Text Then
MsgBox("登录成功")
Else
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
Me.Close()
Dim Conn As String = "provider=Microsoft.jet.oledb.4.0;data source =login.mdb"
Dim MyConn As New OleDb.OleDbConnection
Dim MyDAO As New OleDb.OleDbDataAdapter
MyDAO.TableMappings.Add("Table", "user")
Dim MyCommand As OleDb.OleDbCommand
MyCommand = New OleDb.OleDbCommand("SELECT * FROM userID WHERE 用户名='" & TxtUserName.Text & "'", MyConn)
MyCommand.CommandType = CommandType.Text
MyDAO.SelectCommand = MyCommand
If MyConn.State <> ConnectionState.Open Then
MyConn.ConnectionString = Conn
MyConn.Open()
End If
MyCommand.ExecuteNonQuery()
If MyConn.State <> ConnectionState.Closed Then
MyConn.Close()
End If
MyDAO.Fill(MyDataSet)
If MyDataSet.Tables("user").Rows.Count = 0 Then
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, Me.Text)
Exit Sub
End If
If MyDataSet.Tables("User").Rows(0)("密码").ToString = TxtUserPassword.Text Then
MsgBox("登录成功")
Else
MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Critical, Me.Text)
Exit Sub
End If
Me.Close()