从 Access 数据库中获取文本
Get Text From Access Database
我有从 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
我的 table 装扮在这里
ID Password Name
------- -------- ----
User001 User001 Van
单击按钮后,显示带有文本的消息框,名称来自 Table
问题是,如何从我的 Table 获取姓名记录?
可能您正在寻找这个:
dim positionInResult as Integer = Rd.GetOrdinal("Name")
dim name as String = Rd.GetString(positionInResult)
这假定您不知道如何从 DataReader
中获取 "Name" 值
我有从 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
我的 table 装扮在这里
ID Password Name
------- -------- ----
User001 User001 Van
单击按钮后,显示带有文本的消息框,名称来自 Table
问题是,如何从我的 Table 获取姓名记录?
可能您正在寻找这个:
dim positionInResult as Integer = Rd.GetOrdinal("Name")
dim name as String = Rd.GetString(positionInResult)
这假定您不知道如何从 DataReader
中获取 "Name" 值