Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 05:52 AM
Registered User
 
Join Date: Jan 2007
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 =
ConfigurationSettings.AppSettings("msle02")
               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 =
cmbZone.SelectedItem.Text
               dbComm.Parameters("@Product").Value = cmbProduct.SelectedItem.Text
               dbComm.Parameters("@PFM").Value =
cmbProcessFailMode.SelectedItem.Text
               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
               Else
                       dbComm.Parameters("@Fallout").Value = txtFallout.Text
               End If
               dbComm.Parameters("@Status").Value = cmbStatus.SelectedItem.Text
               dbComm.Parameters("@Comments").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.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: ")
     Response.Write(ex.Message)
         Response.Write("<br>RECORD NOT UPDATED. PLEASE TRY AGAIN OR REPORT
ERROR")
         Response.Write(cmbStatus.SelectedItem.Text)
     Response.End
   Finally
     If objConnection.State = ConnectionState.Open Then
       objConnection.Close()
     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






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 12:45 PM
Err: Cast from String "" to type byte is not valid Parbish BOOK: Beginning VB.NET Databases 1 July 9th, 2005 05: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.