Imports System.Data
Imports System.Data.SqlClient
Module Module1
Public Const strConn As String = "Data Source=AoFza;Initial Catalog=DGE;Integrated Security=True"
Public Conn As New SqlConnection(strConn)
'***********************************
Public tmpUserName As String = ""
'************** frmFixseat *********************
Public tmpsum As String = ""
Public tmpArray As String = ""
Public tmpRow As Integer
Public tmpColumn As Integer
End Module
Code (VB.NET)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim NumberToText As String = ""
Dim sqlGraduate As String = ""
sqlGraduate = "SELECT Graduate.*, Education.* FROM Graduate, Education "
sqlGraduate &= " WHERE (Graduate.EdtID = Education.EdtID)"
sqlGraduate &= " ORDER BY Graduate.GdtHonor,Education.EdtSort " ',Graduate.GdtFname
Da = New SqlDataAdapter(sqlGraduate, Conn)
Da.Fill(Ds, "Graduate")
Dim num As Integer = Ds.Tables("Graduate").Rows.Count
lblMaxGdt.Text = num
Dim cmd As New SqlCommand(sqlGraduate, Conn)
Dim dr As SqlDataReader = cmd.ExecuteReader
With dr
If .HasRows Then
While .Read
Dim liv As New ListViewItem
liv.Text = CType(.Item("GdtID"), String)
liv.SubItems.Add(CType(.Item("EdtID"), String).ToString)
liv.SubItems.Add(CType(.Item("GdtRank"), String).ToString)
liv.SubItems.Add(CType(.Item("GdtTitle"), String).ToString)
liv.SubItems.Add(CType(.Item("GdtFname"), String).ToString)
liv.SubItems.Add(CType(.Item("GdtLname"), String).ToString)
liv.SubItems.Add(CType(.Item("GdtHonor"), String).ToString)
lsvGraduate.Items.Add(liv)
End While
End If
End With
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'MsgBox(tmpArray)
Dim sqlAdd As String = ""
Dim ComAdd As New SqlCommand
Dim i As Integer = 0
For tmpRow = 1 To txtRow.Text
For i = 0 To lsvGraduate.Items.Count - 1
For tmpColumn = 1 To txtColumn.Text
sqlAdd = "INSERT INTO Seat(SeatID,GdtID,RowName)"
sqlAdd &= "VALUES ('" & tmpRow & "',"
sqlAdd &= "'" & Val(lsvGraduate.Items(i).SubItems(0).Text) & "')"
sqlAdd &= "'" & tmpColumn & "')"
MsgBox(sqlAdd)
Next
Next
Next
'With ComAdd
'.CommandType = CommandType.Text
'.CommandText = sqlAdd
'.Connection = Conn
'.ExecuteNonQuery()
MessageBox.Show("บันทึกที่นั่ง เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnAdd.Enabled = True
btnEdit.Enabled = True
btnSave.Enabled = False
btnCancle.Enabled = False
End Sub
Dim J As Integer = 0
Dim K As Integer = lsvGraduate.Items.Count - 1
For tmpRow = 1 To txtRow.Text
For tmpColumn = 1 To txtColumn.Text
If J <= K Then
sqlAdd = "INSERT INTO Seat(SeatID,GdtID,RowName)"
sqlAdd &= "VALUES ('" & tmpRow & "',"
sqlAdd &= "'" & Val(lsvGraduate.Items(J).SubItems(0).Text) & "')"
sqlAdd &= "'" & tmpColumn & "')"
MsgBox(sqlAdd)
J += 1
Else
MsgBox("จัดเก้าอี้กันยังไงวะไม่มีเก้าอี้เหลือให้กูนั้ง")
End If
Next
Next