Private Sub Search_Mem()
Dim sqlmem As String = ""
sqlmem = "SELECT * FROM member"
Select Case coSer.SelectedIndex
Case 0
sqlmem &= " WHERE (Member_ID='" & txtSer.Text & "')"
Case 1
sqlmem &= " WHERE (Name LIKE '%" & txtSer.Text & "%')"
End Select
dt = New DataTable
da = New MySqlDataAdapter(sqlmem, cn)
da.Fill(dt)
If dt.Rows.Count = 1 Then
txtMem.Text = dt.Rows(0).Item("Member_ID")
txtName.Text = dt.Rows(0).Item("Name")
txtLname.Text = dt.Rows(0).Item("Lastname")
ElseIf dt.Rows.Count > 1 Then 'ถ้ามีมากกว่า1 ให้ไปแสดงหน้าค้นหา
Dim Form_searchmem As New FrmSermemShare
Form_searchmem._searchmem = txtSer.Text
Form_searchmem.ShowDialog(Me)
txtMem.ReadOnly = True
txtName.ReadOnly = True
txtLname.ReadOnly = True
ElseIf dt.Rows.Count = 0 Then
MessageBox.Show("ไม่มีข้อมูลสมาชิก", "ตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtSer.Clear()
txtSer.Focus()
Exit Sub
End If
End Sub
โค้ดตอนคลิกส่งค่ากลับ Code (VB.NET)
Private Sub dgSemem_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgSemem.CellMouseDoubleClick
Dim f2 As New frmShare
If e.RowIndex = -1 Then Exit Sub
With dgSemem
f2.txtMem.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString
f2.txtName.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString
f2.txtLname.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString
End With
Me.Close()
End Sub