vb.net 按关键字查询ACCESS数据库
PrivateSubButton7_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesBu...
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim XM As String
XM = InputBox("姓名", "查询")
Dim ConnectionString As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\Administrator\桌面\yqh.mdb"
Dim strsel As String = " select 姓名,性别,年龄,联系方式,工号 from tx1 where 姓名='XM'"
Dim strrow As String = ""
Dim mycon As New OleDbConnection(ConnectionString)
Try
mycon.Open()
MessageBox.Show("已正确连接")
Catch ex As Exception
MessageBox.Show("连接失败")
Exit Sub
End Try
Dim mycom3 As New OleDbCommand
mycom3.Connection = mycon
mycom3.CommandType = CommandType.Text
mycom3.CommandText = strsel
Dim MyDataReader As OleDbDataReader = mycom3.ExecuteReader()
MyDataReader.Read()
Dim i, str1 As Integer
str1 = 0
For i = 0 To 4
strrow = MyDataReader.GetString(i) + " "
str1 = str1 + strrow
Next
Label6.Text = str1
End Sub
我的的思路是这样的,先点击“查询”,然后在Inputbox 中输入姓名,按确定,在label6中显示出 输入姓名人的相关信息
'其中的for 循环是读取各字段下的值,条件是 姓名为我输入的姓名。为什么一直出错。麻烦各位大侠抽一点时间指点指点,不胜感激! 展开
Dim XM As String
XM = InputBox("姓名", "查询")
Dim ConnectionString As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\Administrator\桌面\yqh.mdb"
Dim strsel As String = " select 姓名,性别,年龄,联系方式,工号 from tx1 where 姓名='XM'"
Dim strrow As String = ""
Dim mycon As New OleDbConnection(ConnectionString)
Try
mycon.Open()
MessageBox.Show("已正确连接")
Catch ex As Exception
MessageBox.Show("连接失败")
Exit Sub
End Try
Dim mycom3 As New OleDbCommand
mycom3.Connection = mycon
mycom3.CommandType = CommandType.Text
mycom3.CommandText = strsel
Dim MyDataReader As OleDbDataReader = mycom3.ExecuteReader()
MyDataReader.Read()
Dim i, str1 As Integer
str1 = 0
For i = 0 To 4
strrow = MyDataReader.GetString(i) + " "
str1 = str1 + strrow
Next
Label6.Text = str1
End Sub
我的的思路是这样的,先点击“查询”,然后在Inputbox 中输入姓名,按确定,在label6中显示出 输入姓名人的相关信息
'其中的for 循环是读取各字段下的值,条件是 姓名为我输入的姓名。为什么一直出错。麻烦各位大侠抽一点时间指点指点,不胜感激! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询