Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Cast from string to type Double not valid

Avatar of somorain
somorain asked on
3 Comments1 Solution457 ViewsLast Modified:
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 =
               Dim objConnection As New SqlConnection(strConnection)

               Dim dbComm As New SqlCommand(strSQL, objConnection)

               dbComm.Parameters.Add("@Line", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Zone", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Product", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Shift", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@PFM", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Originator", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@CPM", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@LotID", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@NumReels", SqlDbType.int, 4)
               dbComm.Parameters.Add("@Qty", SqlDbType.int, 4)
               dbComm.Parameters.Add("@ReelID", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Fallout", SqlDbType.int, 4)
               dbComm.Parameters.Add("@Status", SqlDbType.NVarChar, 50)
               dbComm.Parameters.Add("@Comments", SqlDbType.NVarChar, 255)

               dbComm.Parameters("@Line").Value = cmbLine.SelectedItem.Text
               dbComm.Parameters("@Zone").Value =
               dbComm.Parameters("@Product").Value = cmbProduct.SelectedItem.Text
               dbComm.Parameters("@PFM").Value =
               dbComm.Parameters("@Shift").Value = cmbShift.SelectedItem.Text
               dbComm.Parameters("@Originator").Value = txtOriginator.Text
               dbComm.Parameters("@CPM").Value = cmbCPM.SelectedItem.Text
               dbComm.Parameters("@LotID").Value = txtLotID.Text
               dbComm.Parameters("@NumReels").Value = txtNumReels.Text
               dbComm.Parameters("@Qty").Value = txtQty.Text
               dbComm.Parameters("@ReelID").Value = txtReelID.Text
               If txtFallout.Text = "" Then
                       dbComm.Parameters("@Fallout").Value = 0
                       dbComm.Parameters("@Fallout").Value = txtFallout.Text
               End If
               dbComm.Parameters("@Status").Value = cmbStatus.SelectedItem.Text
               dbComm.Parameters("@Comments").Value = txtComments.Text


       Dim iID as Integer

     iID = dbComm.ExecuteNonQuery()
         If (iID = 1) And (cmbStatus.SelectedItem.Value = 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: ")
     If objConnection.State = ConnectionState.Open Then
     End If
   End Try

       If ((cmbStatus.SelectedItem.Value = 4) or
(cmbStatus.SelectedItem.Value = 5) or (cmbStatus.SelectedItem.Value =
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!
Avatar of Pratima Pharande
Pratima PharandeFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers