StrSQL = "INSERT INTO receipt VALUES ("",?Mem_ID,?Rec_Date,?Rec_Total,?Rec_Cash,?Rec_Change)"
For i As Integer = 0 To Rent.DataGridView1.RowCount - 1
If Not Rent.DataGridView1.Rows(i).IsNewRow Then
MyCmd = New MySql.Data.MySqlClient.MySqlCommand(StrSQL, MySQLConn)
With MyCmd
.Parameters.Add(New MySqlParameter("?Mem_ID", Rent.txtMemID.Text))
.Parameters.Add(New MySqlParameter("?Rec_Date", Rent.DataGridView1.Rows(i).Cells(7).Value))
.Parameters.Add(New MySqlParameter("?Rec_Total", lblTotal1.Text))
.Parameters.Add(New MySqlParameter("?Rec_Cash", txtPrice.Text))
.Parameters.Add(New MySqlParameter("?Rec_Change", lblChange.Text))
End With
MyCmd.ExecuteNonQuery()
MyCmd.Parameters.Clear()
End If
Next
MessageBox.Show("บันทึกข้อมูลแล้ว", "บันทึกข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
MySQLConn.Close()
MySQLConn = Nothing
Call Rent.clearData()
Me.Close()
'frmRec.Show()
End Sub
Tag : .NET, MySQL, Win (Windows App), VB.NET, VS 2012 (.NET 4.x)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Call Conntion()
Dim ID As Integer
StrSQL = "INSERT INTO rent VALUES (" & ID & ",?Mem_ID,?Mem_FName,?Mem_LName,?Mem_Phone,?Book_ID,?Barcode_ID,?Book_NameTH,?Book_NameEN,?dateStart,?dateEnd)"
For i As Integer = 0 To Rent.DataGridView1.RowCount - 1
If Not Rent.DataGridView1.Rows(i).IsNewRow Then
MyCmd = New MySql.Data.MySqlClient.MySqlCommand(StrSQL, MySQLConn)
With MyCmd
.Parameters.Add(New MySqlParameter("?Mem_ID", Rent.txtMemID.Text))
.Parameters.Add(New MySqlParameter("?Mem_FName", Rent.txtName.Text))
.Parameters.Add(New MySqlParameter("?Mem_LName", Rent.txtLName.Text))
.Parameters.Add(New MySqlParameter("?Mem_Phone", Rent.txtPhoneNumber.Text))
.Parameters.Add(New MySqlParameter("?Book_ID", Rent.DataGridView1.Rows(i).Cells(0).Value))
.Parameters.Add(New MySqlParameter("?Barcode_ID", Rent.DataGridView1.Rows(i).Cells(1).Value))
.Parameters.Add(New MySqlParameter("?Book_NameTH", Rent.DataGridView1.Rows(i).Cells(2).Value))
.Parameters.Add(New MySqlParameter("?Book_NameEN", Rent.DataGridView1.Rows(i).Cells(3).Value))
.Parameters.Add(New MySqlParameter("?dateStart", Rent.DataGridView1.Rows(i).Cells(7).Value))
.Parameters.Add(New MySqlParameter("?dateEnd", Rent.DataGridView1.Rows(i).Cells(8).Value))
End With
MyCmd.ExecuteNonQuery()
MyCmd.Parameters.Clear()
End If
Next
'Dim Rec_ID As Integer
StrSQL = "INSERT INTO receipt VALUES ("",?Mem_ID,?Rec_Date,?Rec_Total,?Rec_Cash,?Rec_Change)"
For i As Integer = 0 To Rent.DataGridView1.RowCount - 1
If Not Rent.DataGridView1.Rows(i).IsNewRow Then
MyCmd = New MySql.Data.MySqlClient.MySqlCommand(StrSQL, MySQLConn)
With MyCmd
.Parameters.Add(New MySqlParameter("?Mem_ID", Rent.txtMemID.Text))
.Parameters.Add(New MySqlParameter("?Rec_Date", Rent.DataGridView1.Rows(i).Cells(7).Value))
.Parameters.Add(New MySqlParameter("?Rec_Total", lblTotal1.Text))
.Parameters.Add(New MySqlParameter("?Rec_Cash", txtPrice.Text))
.Parameters.Add(New MySqlParameter("?Rec_Change", lblChange.Text))
End With
MyCmd.ExecuteNonQuery()
MyCmd.Parameters.Clear()
End If
Next
MessageBox.Show("บันทึกข้อมูลแล้ว", "บันทึกข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
MySQLConn.Close()
MySQLConn = Nothing
Call Rent.clearData()
Me.Close()
'frmRec.Show()
End Sub