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)
                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)
        Catch ex As Exception
            MessageBox.Show("Order Successfully Added")
        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.

First off, you are saying the operation is successful if there is an error (Line 35). I don't get that. I would place a Msgbox that gets the ex.ToString property there so you can see the line number of the error as well as the error itself.

Next, you are reading values from the command with an ExecuteReader, but you are executing an Insert statement (Line 31). You should execute the Scalar method (cmd.ExecuteScalar).

This article has been dead for over six months. Start a new discussion instead.