MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "Server=localhost;User Id=root;Password=p@ssw0rd;Database=db_bill"
MysqlConn.Open()
Dim Query1 As String
Query1 = "insert into bill_detail(id_bill,name_pd,price_pd,quantity) values(@id_bill,@name_pd,@price_pd,@quantity)"
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
objCmd = New MySqlCommand(Query1, MysqlConn)
With objCmd
.Parameters.Add(New MySqlParameter("@id_bill", TextBox11.Text))
.Parameters.Add(New MySqlParameter("@name_pd", DataGridView1.Rows(i).Cells(0).Value))
.Parameters.Add(New MySqlParameter("@quantity", DataGridView1.Rows(i).Cells(1).Value))
.Parameters.Add(New MySqlParameter("@price_pd", DataGridView1.Rows(i).Cells(2).Value))
End With
objCmd.ExecuteNonQuery()
End If
Next
MessageBox.Show("บันทึกข้อมูลแล้ว")
MysqlConn.Close()
DataGridView1.Rows.Clear()