Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim strsql As String
Dim dt As New DataTable
Dim dt1 As New DataTable
Dim dtAdapter As SqlDataAdapter
Dim CSub As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strsql = "Data Source=localhost;Initial Catalog=ClassRoom;Persist Security Info=True;User ID=sa;Password=friend16"
con.ConnectionString = strsql
con.Open()
strsql = "select Subject.SubjectID , Subject.SubjectName ,Subject.Sec from Teaching inner join Subject on Subject.SubjectID = Teaching.SubjectID "
dtAdapter = New SqlDataAdapter(strsql, con)
dtAdapter.Fill(dt)
Me.DGV_Subject.DataSource = dt
'con.Close()
'con = Nothing
With DGV_Subject
.AllowUserToAddRows = False
.BorderStyle = BorderStyle.None
.Columns(1).HeaderText = "รหัสวิชา"
.Columns(1).Width = 100
.Columns(2).HeaderText = "ชื่อวิชา"
.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns(3).HeaderText = "หมู่เรียน"
.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Me.Hide()
End Sub
End Class
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Dim gr As DataGridView = DataGridView1
For index As Integer = 0 To DataGridView1.Rows.Count - 1
If (gr.Rows(index).Cells(0).Value <> Nothing) Then 'checked
MessageBox.Show("1 " + gr.Rows(index).Cells(2).Value.ToString())
Else
MessageBox.Show("0 " + gr.Rows(index).Cells(2).Value.ToString())
End If
'MessageBox.Show("Rows " + dr.Index.ToString() + " selected")
Next
End Sub