I am currently stuck on a project where I am populating a datagrid from a series of labels and textboxes. I have that part down. Now for the part where I actually add it do the database, I am having a problem. It is actually adding everything to the database just like I want it but when it finishes adding the data from the datagridview, I am getting an error saying there are no values. I have tried numerous things and nothing helps.
I have included the code I have been working with. I appreciate any help I can get on this.
Thanks
Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
Dim I As Integer
For I = 0 To DataGridView1.Rows.Count - 1
Dim itemname As String = DataGridView1.Rows(I).Cells(0).Value
Dim quantity As String = DataGridView1.Rows(I).Cells(1).Value
Dim totalcost As String = DataGridView1.Rows(I).Cells(2).Value
Dim barcode As String = DataGridView1.Rows(I).Cells(3).Value
Dim ordernumber As String = DataGridView1.Rows(I).Cells(4).Value
Dim orderdate As String = DataGridView1.Rows(I).Cells(5).Value
Dim buyinprice As String = DataGridView1.Rows(I).Cells(6).Value
Dim saleprice As String = DataGridView1.Rows(I).Cells(7).Value
Dim vendorname As String = DataGridView1.Rows(I).Cells(8).Value
Dim status As String = DataGridView1.Rows(I).Cells(9).Value
Dim RepairNumber As String = DataGridView1.Rows(I).Cells(10).Value
Dim conn As New SqlConnection("*******")
Dim query As String = "Insert Into orders(Itemname, Quantity, totalcost, barcode, ordernumber, orderdate, buyinprice, saleprice, vendorname, status, RepairNumber) values (@Itemname, @Quantity, @totalcost, @barcode, @ordernumber, @orderdate, @buyinprice, @saleprice, @vendorname, @status, @RepairNumber)"
Dim cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@itemname", itemname)
cmd.Parameters.AddWithValue("@Quantity", quantity)
cmd.Parameters.AddWithValue("@totalcost", totalcost)
cmd.Parameters.AddWithValue("@barcode", barcode)
cmd.Parameters.AddWithValue("@ordernumber", ordernumber)
cmd.Parameters.AddWithValue("@orderdate", orderdate)
cmd.Parameters.AddWithValue("@buyinprice", buyinprice)
cmd.Parameters.AddWithValue("@saleprice", saleprice)
cmd.Parameters.AddWithValue("@vendorname", vendorname)
cmd.Parameters.AddWithValue("@status", status)
cmd.Parameters.AddWithValue("@repairnumber", RepairNumber)
conn.Open()
cmd.Executenonquery()
conn.Dispose()
Next
If I <= 0 Then
MessageBox.Show("Items Added Fool")
DataGridView1.Refresh()