vb.net 数据库中一个问题
ImportsSystem.Data.OleDbPublicClassForm1PublicmybindAsBindingManagerBasePrivateProper...
Imports System.Data.OleDb
Public Class Form1
Public mybind As BindingManagerBase
Private Property mydataset As DataSet
Private Property mybid As BindingManagerBase
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "provider=Microsoft.ACE.OLEDB.12.0;" & "data source =F:\student.accdb"
Dim myconn As OleDbConnection = New OleDbConnection()
myconn.ConnectionString = strcon
'
Dim strcom As String = "select 学 * from 表2 WHERE 学号='"& textbox1.text"&'"
Dim mydataset As New DataSet()
myconn.Open()
Dim mycommand As OleDbDataAdapter = New OleDbDataAdapter(strcom, strcon)
mycommand.Fill(mydataset, "表2")
myconn.Close()
mybind = Me.BindingContext(mydataset, "表2")
Me.DataGridView1.DataSource = mydataset.Tables("表2")
End Sub
End Class
我用上面的方法查询当数据库中学号等于 textbox1.text 时,所有成员信息,将他们显示到.DataGridView1中,但是,我现在想让信息显示到 几个textbox中(比如:姓名显示到textbox2,性别显示到textbox3等等,不知道怎么弄,请大神帮帮忙吧!! 展开
Public Class Form1
Public mybind As BindingManagerBase
Private Property mydataset As DataSet
Private Property mybid As BindingManagerBase
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "provider=Microsoft.ACE.OLEDB.12.0;" & "data source =F:\student.accdb"
Dim myconn As OleDbConnection = New OleDbConnection()
myconn.ConnectionString = strcon
'
Dim strcom As String = "select 学 * from 表2 WHERE 学号='"& textbox1.text"&'"
Dim mydataset As New DataSet()
myconn.Open()
Dim mycommand As OleDbDataAdapter = New OleDbDataAdapter(strcom, strcon)
mycommand.Fill(mydataset, "表2")
myconn.Close()
mybind = Me.BindingContext(mydataset, "表2")
Me.DataGridView1.DataSource = mydataset.Tables("表2")
End Sub
End Class
我用上面的方法查询当数据库中学号等于 textbox1.text 时,所有成员信息,将他们显示到.DataGridView1中,但是,我现在想让信息显示到 几个textbox中(比如:姓名显示到textbox2,性别显示到textbox3等等,不知道怎么弄,请大神帮帮忙吧!! 展开
1个回答
展开全部
Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
If Me.DataGridView1.SelectedRows.Count > 0 Then
TextBox1.Text = Me.DataGridView1.SelectedRows(0).Cells("列名").Value.ToString
End If
End Sub
这是在DataGridView1激发单击事件,在TextBox1中显示选中的那行中的某个单元格的值。
如果有TextBox2、TextBox3等乖,以此类推。
更多追问追答
追问
那如果想不单击DataGridView1而直接在textbox中显示,可以做到吗???
追答
既然使用datagridview控件,说明数据是一个表,有很多条数据.
textbox只能显示一个单元格的数据,你想怎么让数据直接显示在textbox中?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询