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
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.
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()
Thanks for the Help.