Try
Dim I As Integer
For I = 0 To DataGridView1.Rows.Count - 1
Dim ordernumber As String = DataGridView1.Rows(I).Cells(0).Value
Dim repairinvoice As String = DataGridView1.Rows(I).Cells(1).Value
Dim itemname As String = DataGridView1.Rows(I).Cells(2).Value
Dim orderedquantity As String = DataGridView1.Rows(I).Cells(3).Value
Dim itemcost As String = DataGridView1.Rows(I).Cells(4).Value
Dim saleprice As String = DataGridView1.Rows(I).Cells(5).Value
Dim status As String = DataGridView1.Rows(I).Cells(6).Value
Dim vendorname As String = DataGridView1.Rows(I).Cells(7).Value
Dim description As String = DataGridView1.Rows(I).Cells(8).Value
Dim totalcost As String = Label3.Text
Dim orderdate As String = Label28.Text
Dim conn As New SqlConnection(My.Settings.Smitty)
conn.Open()
Dim query As String = "Insert Into repairinventry(ordernumber, RepairInvoice, Itemname, orderedquantity, buycost, sellcost, status, vendorname, description, totalcost, orderdate) values (@ordernumber, @RepairInvoice, @Itemname, @orderedquantity, @buycost, @sellcost, @status, @vendorname, @description, @totalcost, @orderdate)"
Dim cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@ordernumber", ordernumber)
cmd.Parameters.AddWithValue("@repairinvoice", repairinvoice)
cmd.Parameters.AddWithValue("@itemname", itemname)
cmd.Parameters.AddWithValue("@orderedquantity", orderedquantity)
cmd.Parameters.AddWithValue("@itemcost", itemcost)
cmd.Parameters.AddWithValue("@saleprice", saleprice)
cmd.Parameters.AddWithValue("@status", status)
cmd.Parameters.AddWithValue("@vendorname", vendorname)
cmd.Parameters.AddWithValue("@description", description)
cmd.Parameters.AddWithValue("@totalcost", totalcost)
cmd.Parameters.AddWithValue("@orderdate", orderdate)
cmd.ExecuteReader()
cmd.Dispose()
Next
Catch ex As Exception
MessageBox.Show("Order Successfully Added")
DataGridView1.Rows.Clear()
End Try
End Sub
I had a question about this three months ago and got it figured out. However, my home burned down and I am in the process of rewriting my system as I had no back ups. Unfortunately when I use this code, it is not doing anything but giving me a messagebox. Basically all I am attempting to do is insert all the columns from this datagridview into my database. It is like it doesn't even attempt to do the SQL command. I appreciate any help on this.