从Access数据库获取文本

时间:2015-05-19 10:27:20

标签: database vb.net ms-access ms-access-2007

我有从Access数据库中读取数据的代码

Imports System.Data.OleDb
    Public Class Form2
        Dim CMD As OleDbConnection
        Dim RD As OleDbDataReader
        Dim Go As OleDbCommand
        Dim i As Integer = 0
        Dim a As Integer = 0
        Dim r As Integer = 0
    Private Sub BT1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT1.Click
            If My.Computer.Network.IsAvailable Then
                Call Connect()
                Go = New OleDbCommand("select * from Account where ID='" & TxtID.Text & "' and Password='" & TxtPw.Text & "'", Conn)
                RD = Go.ExecuteReader
                If RD.Read Then
                    Menu1.Show()
                    Form1.Hide()
                    Me.Close()
                Else
                    MessageBox.Show("ID or Password is Incorrect!", "InCorrect", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else

            End If
        End Sub

我的表看起来就在这里

ID      Password Name  
------- -------- ----
User001 User001  Van  

单击该按钮时,显示带有文本的消息框,表格中的名称

问题是,如何从我的表中获取姓名记录?

1 个答案:

答案 0 :(得分:0)

可能你正在寻找这个:

dim positionInResult as Integer = Rd.GetOrdinal("Name")
dim name as String = Rd.GetString(positionInResult)

这假设您不知道如何从DataReader中获取“Name”值