somorain
asked on
Cast from string to type Double not valid
I've got a drop down list on an asp.net form and I'm inserting the
selected text to a an SQL Server database but i'm encountering the
error 'Cast from string "On Hold" to type 'Double' is not valid.'
This is the code:
Sub btnSubmit_Click(Sender As Object, E As EventArgs)
'If Not IsPostBack Then
If Page.IsValid Then
Dim strSQL As String
strSQL = "UPDATE tbl_THA SET " & _
"Line_No = @Line, " & _
"Zone = @Zone, " & _
"Product = @Product, " & _
"Process_Fail_Mode = @PFM, " & _
"CPM = @CPM, " & _
"Lot_Id = @LotID, " & _
"No_of_Reels_on_Hold = @NumReels, " & _
"Qty_On_Hold = @Qty, " & _
"Reel_Id = @ReelID, " & _
"Fallout = @Fallout, " & _
"Status = @Status, " & _
"Operations_Comments = @Comments " & _
"WHERE THA_on_hold_No = "&txtTHA_No.Text
Dim strConnection As String =
ConfigurationSettings.AppS ettings("m sle02")
Dim objConnection As New SqlConnection(strConnectio n)
Dim dbComm As New SqlCommand(strSQL, objConnection)
dbComm.Parameters.Add("@Li ne", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Zo ne", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Pr oduct", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Sh ift", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@PF M", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Or iginator", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@CP M", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Lo tID", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Nu mReels", SqlDbType.int, 4)
dbComm.Parameters.Add("@Qt y", SqlDbType.int, 4)
dbComm.Parameters.Add("@Re elID", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Fa llout", SqlDbType.int, 4)
dbComm.Parameters.Add("@St atus", SqlDbType.NVarChar, 50)
dbComm.Parameters.Add("@Co mments", SqlDbType.NVarChar, 255)
dbComm.Parameters("@Line") .Value = cmbLine.SelectedItem.Text
dbComm.Parameters("@Zone") .Value =
cmbZone.SelectedItem.Text
dbComm.Parameters("@Produc t").Value = cmbProduct.SelectedItem.Te xt
dbComm.Parameters("@PFM"). Value =
cmbProcessFailMode.Selecte dItem.Text
dbComm.Parameters("@Shift" ).Value = cmbShift.SelectedItem.Text
dbComm.Parameters("@Origin ator").Val ue = txtOriginator.Text
dbComm.Parameters("@CPM"). Value = cmbCPM.SelectedItem.Text
dbComm.Parameters("@LotID" ).Value = txtLotID.Text
dbComm.Parameters("@NumRee ls").Value = txtNumReels.Text
dbComm.Parameters("@Qty"). Value = txtQty.Text
dbComm.Parameters("@ReelID ").Value = txtReelID.Text
If txtFallout.Text = "" Then
dbComm.Parameters("@Fallou t").Value = 0
Else
dbComm.Parameters("@Fallou t").Value = txtFallout.Text
End If
dbComm.Parameters("@Status ").Value = cmbStatus.SelectedItem.Tex t
dbComm.Parameters("@Commen ts").Value = txtComments.Text
'Response.Write(strSQL)
Dim iID as Integer
Try
objConnection.Open()
iID = dbComm.ExecuteNonQuery()
'Response.Write(iID)
If (iID = 1) And (cmbStatus.SelectedItem.Va lue = 2) Then
lblStatus.Text = "Record Updated. Please modify barcode."
lblStatus3.Text = "="
btnSubmit.Enabled = false
Else If (iID = 1) Then
lblStatus.Text = "Record Updated."
btnSubmit.Enabled = false
End If
Catch ex As Exception
'If ex.Message =
Response.Write("An error has occurred: ")
Response.Write(ex.Message)
Response.Write("<br>RECORD NOT UPDATED. PLEASE TRY AGAIN OR REPORT
ERROR")
Response.Write(cmbStatus.S electedIte m.Text)
Response.End
Finally
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If
End Try
If ((cmbStatus.SelectedItem.V alue = 4) or
(cmbStatus.SelectedItem.Va lue = 5) or (cmbStatus.SelectedItem.Va lue =
6)) Then
btnClose.Enabled = True
End If
End If
End Sub
The drop down list is populated with 5 text values in the page load
sub. The strange thing is if I change the value in the list, I don't
get the error. It only occurs if I leave the selected item as it is
when the page loads.
I can't understand why its trying to change to type Double in the
first place. I don't have any Cast statements and the data type in the
db is nvarchar(50).
Any help is greatly appreciated!
selected text to a an SQL Server database but i'm encountering the
error 'Cast from string "On Hold" to type 'Double' is not valid.'
This is the code:
Sub btnSubmit_Click(Sender As Object, E As EventArgs)
'If Not IsPostBack Then
If Page.IsValid Then
Dim strSQL As String
strSQL = "UPDATE tbl_THA SET " & _
"Line_No = @Line, " & _
"Zone = @Zone, " & _
"Product = @Product, " & _
"Process_Fail_Mode = @PFM, " & _
"CPM = @CPM, " & _
"Lot_Id = @LotID, " & _
"No_of_Reels_on_Hold = @NumReels, " & _
"Qty_On_Hold = @Qty, " & _
"Reel_Id = @ReelID, " & _
"Fallout = @Fallout, " & _
"Status = @Status, " & _
"Operations_Comments = @Comments " & _
"WHERE THA_on_hold_No = "&txtTHA_No.Text
Dim strConnection As String =
ConfigurationSettings.AppS
Dim objConnection As New SqlConnection(strConnectio
Dim dbComm As New SqlCommand(strSQL, objConnection)
dbComm.Parameters.Add("@Li
dbComm.Parameters.Add("@Zo
dbComm.Parameters.Add("@Pr
dbComm.Parameters.Add("@Sh
dbComm.Parameters.Add("@PF
dbComm.Parameters.Add("@Or
dbComm.Parameters.Add("@CP
dbComm.Parameters.Add("@Lo
dbComm.Parameters.Add("@Nu
dbComm.Parameters.Add("@Qt
dbComm.Parameters.Add("@Re
dbComm.Parameters.Add("@Fa
dbComm.Parameters.Add("@St
dbComm.Parameters.Add("@Co
dbComm.Parameters("@Line")
dbComm.Parameters("@Zone")
cmbZone.SelectedItem.Text
dbComm.Parameters("@Produc
dbComm.Parameters("@PFM").
cmbProcessFailMode.Selecte
dbComm.Parameters("@Shift"
dbComm.Parameters("@Origin
dbComm.Parameters("@CPM").
dbComm.Parameters("@LotID"
dbComm.Parameters("@NumRee
dbComm.Parameters("@Qty").
dbComm.Parameters("@ReelID
If txtFallout.Text = "" Then
dbComm.Parameters("@Fallou
Else
dbComm.Parameters("@Fallou
End If
dbComm.Parameters("@Status
dbComm.Parameters("@Commen
'Response.Write(strSQL)
Dim iID as Integer
Try
objConnection.Open()
iID = dbComm.ExecuteNonQuery()
'Response.Write(iID)
If (iID = 1) And (cmbStatus.SelectedItem.Va
lblStatus.Text = "Record Updated. Please modify barcode."
lblStatus3.Text = "="
btnSubmit.Enabled = false
Else If (iID = 1) Then
lblStatus.Text = "Record Updated."
btnSubmit.Enabled = false
End If
Catch ex As Exception
'If ex.Message =
Response.Write("An error has occurred: ")
Response.Write(ex.Message)
Response.Write("<br>RECORD
ERROR")
Response.Write(cmbStatus.S
Response.End
Finally
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If
End Try
If ((cmbStatus.SelectedItem.V
(cmbStatus.SelectedItem.Va
6)) Then
btnClose.Enabled = True
End If
End If
End Sub
The drop down list is populated with 5 text values in the page load
sub. The strange thing is if I change the value in the list, I don't
get the error. It only occurs if I leave the selected item as it is
when the page loads.
I can't understand why its trying to change to type Double in the
first place. I don't have any Cast statements and the data type in the
db is nvarchar(50).
Any help is greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Trace/Debug the value of strSQL, and run it in query analyser, you will find the point of error.
ASKER
On closer inspection, there was a - between on and hold in my drop down list.
Thanks for the advice, it helped a lot.
Thanks for the advice, it helped a lot.