Dear attached is my project I wanted to store rows from datagridview to mysql table but I am facing the error in the image kindly help me.
http://ansicollege.net/vbcode/error.png[
^]
This the error I get.
Following is the code line I get error in
dgvcc = DirectCast(DataGridView1.Rows(i).Cells(1), DataGridViewComboBoxCell)
.Parameters.AddWithValue("@product", dgvcc.Value)
I store values in combobox of Datagridview, product_id datatype in database is int
Here is my project
http://ansicollege.net/vbcode/TsoftPOS.zip[
^]
What I have tried:
Public Sub CreateBill()
Dim sql2 As String
Try
ConnDB()
Dim dgvcc As New DataGridViewComboBoxCell
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
sqL = "INSERT INTO `dailysale`(`billno`,`customer_id`, `product_id`, `qty`, `price`, `total`, `description`) VALUES(@billno,@custid,@product, @qty, @price, @total, @desc)"
cmd = New MySqlCommand(sqL, conn)
With cmd
.Parameters.AddWithValue("@billno", txtbillno.Text)
.Parameters.AddWithValue("@custid", txtCustomer.Tag)
dgvcc = DirectCast(DataGridView1.Rows(i).Cells(1), DataGridViewComboBoxCell)
.Parameters.AddWithValue("@product", dgvcc.Value)
.Parameters.AddWithValue("@qty", Me.DataGridView1.Rows(i).Cells(2).Value)
.Parameters.AddWithValue("@price", Me.DataGridView1.Rows(i).Cells(3).Value)
.Parameters.AddWithValue("@total", Me.DataGridView1.Rows(i).Cells(4).Value)
.Parameters.AddWithValue("@desc", Me.DataGridView1.Rows(i).Cells(5).Value)
End With
cmd.ExecuteNonQuery()
Next
sql2 = "INSERT INTO customer_payments(customer_id, billno, cdate, bill_amount, paid_amount, discount, ret_amount, balance) VALUES ('" & txtCustomer.Tag & "','" & txtbillno.Text & "','" & DateTimePicker1.Value & "','" & txtbill_amount.Text & "','" & txtpaid_amount.Text & "','" & txtdiscount.Text & "','" & txtret_amount.Text & "','" & txttotalbalance.Text & "')"
cmd = New MySqlCommand(sqL, conn)
cmd.ExecuteNonQuery()
MsgBox("New Bill successfully created.", MsgBoxStyle.Information, "Create Bill")
Catch ex As Exception
MsgBox(ex.ToString)
Finally
cmd.Dispose()
conn.Close()
End Try