Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

VS 2008 SQL Code Executing without Error, Not Writing

$
0
0
I am using a SQL Code to write to the Database based on Data In the DataGrid. It is pulling the Data From the DataGrid Correctly, but Not writing to the DataBase. Here is the code
Code:

  Dim MAXLine1Statement As String = "SELECT MAX(LineNumber) FROM ProductionLines WHERE ProductionKey = @ProductionKey"
            Dim MAXLine1Command As New SqlCommand(MAXLine1Statement, con)
            MAXLine1Command.Parameters.Add("@ProductionKey", SqlDbType.VarChar).Value = Val(cboProductionKey.Text)

                  If con.State = ConnectionState.Closed Then con.Open()

                                LastLineNumber = CInt(MAXLine1Command.ExecuteScalar)

                                con.Close()

                                NextLineNumber = LastLineNumber + 1

                           
                               
                                    cmd = New SqlCommand("Insert Into ProductionLines(ProductionKey, LineNumber, Part, PartDescription, Quantity, Cost, ExtendedCost, LineWeight) Values(@ProductionKey, @LineNumber, @Part, @PartDescription, @Quantity, @Cost, @ExtendedCost, @LineWeight)", con)

                                    With cmd.Parameters
                                        .Add("@ProductionKey", SqlDbType.VarChar).Value = Val(cboProductionKey.Text)
                                        .Add("@LineNumber", SqlDbType.VarChar).Value = NextLineNumber
                                        .Add("@Part", SqlDbType.VarChar).Value = TapeType
                                        .Add("@PartDescription", SqlDbType.VarChar).Value = "TAPE"
                                        .Add("@Quantity", SqlDbType.VarChar).Value = LineQuantity * -1
                                        .Add("@Cost", SqlDbType.VarChar).Value = TapeCost
                                        .Add("@ExtendedCost", SqlDbType.VarChar).Value = LineQuantity * TapeCost * -1
                                        .Add("@LineWeight", SqlDbType.VarChar).Value = LineWeight
                                    End With

                                    If con.State = ConnectionState.Closed Then con.Open()
                                    cmd.ExecuteNonQuery()
                                    con.Close()

I have message boxes telling me the values, and they are the correct values for the DataType and for the DataBase.
Thanks for the Help.

Viewing all articles
Browse latest Browse all 42215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>