Imports System.Data.SqlClient
Public Class Form2
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim strsql As String
Dim strsql1 As String
Dim dt As New DataTable
Dim dt1 As New DataTable
Dim dtAdapter As SqlDataAdapter
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strsql = "Data Source=localhost; Initial Catalog=KU_OCR; Integrated Security= true"
con.ConnectionString = strsql
con.Open()
strsql = "Select * from Teacher"
dtAdapter = New SqlDataAdapter(strsql, con)
dtAdapter.Fill(dt)
Me.DataGridView1.DataSource = dt
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim aa As String
If e.RowIndex = -1 Then Exit Sub
With DataGridView1
aa = .Rows.Item(e.RowIndex).Cells(0).Value.ToString
TextBox1.Text = aa
strsql1 = "Select * from Teaching where teac_id = '" & aa & "' "
dtAdapter = New SqlDataAdapter(strsql1, con)
dtAdapter.Fill(dt1)
Me.DataGridView2.DataSource = dt1
End With
End Sub
End Class