Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
Thread Tools Display Modes
  #1 (permalink)  
Old January 31st, 2007, 05:52 AM
Registered User
Join Date: Jan 2007
Location: Galway, , Ireland.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast from string to type Double not valid

I've got a drop down list on an asp 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

Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from string 'OPEN' to type 'Double' is not va yasinirshad .NET Framework 1.x 1 August 12th, 2007 01:45 PM
Err: Cast from String "" to type byte is not valid Parbish BOOK: Beginning VB.NET Databases 1 July 9th, 2005 06:43 PM
Cast from string "" to type 'Double' is not dounme ADO.NET 1 March 8th, 2005 01:31 PM
Cast from string "" to type 'Double' is not dounme SQL Server 2000 1 February 18th, 2005 01:44 AM
Cast from string "" to type 'Integer' is not valid h3x SQL Server ASP 1 January 30th, 2005 09:35 PM

All times are GMT -4. The time now is 03:35 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.