我有VB.net项目,我需要使用urno进行搜索,它应该在表单上的所有文本框和组合框中填充信息,它与数据存储在数据库中的形式相同。代码是
Public Class MBAUpdate
Dim con As New OleDb.OleDbConnection()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'Dim da As OleDb.OleDbDataAdapter
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection()
con.ConnectionString = dbprovider
con.Open()
Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
Dim sqlcommand As New OleDb.OleDbCommand(sqlquery, con)
Dim ds As DataSet
With sqlcommand
.CommandText = sqlquery
.Connection = con
.ExecuteReader()
End With
' MsgBox("Record Added")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
任何想法如何实现这一点确实相当谷歌搜索没有帮助....
答案 0 :(得分:0)
找到一种方法来做它和它的工作就像一个魅力......
Public Class MBAUpdate
Dim con As New OleDb.OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'Dim da As OleDb.OleDbDataAdapter
Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
Me.con = New OleDb.OleDbConnection
Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
Dim command As New OleDb.OleDbCommand(sqlquery, con)
Dim reader As OleDb.OleDbDataReader
con.ConnectionString = dbprovider
con.Open()
reader = command.ExecuteReader()
reader.Read()
txtName.Text = reader(1).ToString()
txtFname.Text = reader(2).ToString()
txtCAdd.Text = reader(3).ToString()
txtPAdd.Text = reader(4).ToString()
txtEid.Text = reader(5).ToString()
cmbGender.Text = reader(6).ToString()
txtMno.Text = reader(7).ToString()
' MsgBox("Record Added")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class