我有一个名为“搜索”的表单,带有 2 个文本框、datagridview 和一个按钮。当我在第一个文本框 ["txtemployee_search"] 中输入任何关键字(例如我想要的名称)时,它会过滤绑定到员工表的 datagridview [dgvemployee] 项目。所以当我选择我要查找的名称时,它会显示在第二个文本框中[“txtemp_search_selection”]。但我的问题是,我想显示或打开第二个表格,其中包含与第二个文本框中的名称相关的姓名、年龄、性别、图片、电话等详细信息我点击按钮。我正在使用 vb 2008 和 sql server 2005。我需要帮助!
下面是我的代码
Imports System.Data.SqlClient
Public Class employee_search
'THE CODE TO SEARCH DATAGRID WHILE TYPING INTO FIRST TEXTBOX
Private Sub txtemployee_search_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtemployee_search.TextChanged
Dim keywords As String = txtemployee_search.Text
Dim con As SqlConnection = New SqlConnection("Data Source=oheneba;Initial Catalog=brainiac;Persist Security Info=True;User ID=sa;Password=***********")
' Use wildcard
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Employee WHERE Full_Name Like '%" & keywords & "%' ", con)
' or Where Full_Name='" & keywords & "'
con.Open()
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Employee")
dgvemployee.DataSource = myDataSet.Tables("Employee").DefaultView
con.Close()
End Sub
'将选定的 DATAGRIDVIEW 项目显示到第二个文本框中的代码
Private Sub dgvemployee_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvemployee.CellContentClick
Dim dgv As DataGridView = CType(sender, DataGridView)
Dim thisCell As DataGridViewCell = dgv.SelectedCells(0)
Dim selCell As Integer = thisCell.ColumnIndex
txtemp_search_selection.Text = dgvemployee.CurrentRow.Cells(selCell).Value.ToString()
End Sub