StoredProc error - insert - Input string was not in a correct format. RRS feed

  • Question

  • User-29418745 posted

    I have a an asp.net page that sits inside and an iframe. The .net page gets values from the parent page using javascript and places these values into hidden fields.

    when the page is submited these values are to be inserted into sql using a storedProc, however when I run it I'm getting

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error:

    Line 72:             Dim dbCommandWrapper As DBCommandWrapper = db.GetStoredProcCommandWrapper("signup")
    Line 73: 'dbCommandWrapper.AddInParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, Nothing)
    Line 74: dbCommandWrapper.AddInParameter("@Email", strEmail)
    Line 75: 'dbCommandWrapper.AddInParameter("@Dept", System.Data.SqlDbType.VarChar, 3)
    Line 76: dbCommandWrapper.AddInParameter("@Lang", strLang)
    Here is my code, would really appreciate if someone can tell me what i"m dong wrong.

    Imports Microsoft.Practices.EnterpriseLibrary.Configuration
    Imports Microsoft.Practices.EnterpriseLibrary.Data

    Public Class insert
        Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
        End Sub

    #End Region

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here

            'Declare vars and assign values
            'Values are gathered from hidden fields
            'Hidden Fields get value from javascript from Skylights.
            Dim strEmail As String = Request.Form("myHiddenField")
            Dim strFirstName As String = Request.Form("fName")
            Dim strSurname As String = Request.Form("sName")
            Dim strPort As String
            Dim strLang As String = Request.Form("lang")
            Dim subscribe As String

            RegisterHiddenField("myHiddenField", "javascript:document.Form1.myHiddenField.value = emailVar;")
            RegisterHiddenField("fName", "javascript:document.Form1.fName.value = firstNameVar;")
            RegisterHiddenField("sName", "javascript:document.Form1.sName.value = surnameVar;")
            RegisterHiddenField("lang", "javascript:document.Form1.lang.value = langVar;")

            If Page.IsPostBack Then

                CheckBox1.Text = Request.Form("myHiddenField")

                'If CheckBox1.Checked Then
                '    subscribe = "1"
                'Else : subscribe = "0"
                'End If

                'Dim sqlCommand
                Dim db As Database = DatabaseFactory.CreateDatabase("Database Instance")
                Dim productsDataSet As DataSet = New DataSet

                'inline SQL
                'Dim sqlCommand As String = "Insert into [EMAIL-SIGNUP] (email, firstname, lastname, subscribe, languagecode) values ('" & strEmail & "', '" & strFirstName & "', '" & strSurname & "', '" & subscribe & "', '" & strLang & "')"
                'Dim dbCommandWrapper As DBCommandWrapper = db.GetSqlStringCommandWrapper(sqlCommand)

                Dim dbCommandWrapper As DBCommandWrapper = db.GetStoredProcCommandWrapper("signup")
                'dbCommandWrapper.AddInParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, Nothing)
                dbCommandWrapper.AddInParameter("@Email", strEmail)
                'dbCommandWrapper.AddInParameter("@Dept", System.Data.SqlDbType.VarChar, 3)
                dbCommandWrapper.AddInParameter("@Lang", strLang)
                dbCommandWrapper.AddInParameter("@Blacklist", System.Data.SqlDbType.Bit, 1)
                dbCommandWrapper.AddInParameter("@firstname", strFirstName)
                dbCommandWrapper.AddInParameter("@lastname", strSurname)
                dbCommandWrapper.AddInParameter("@campaign", System.Data.SqlDbType.VarChar, 150)
                dbCommandWrapper.AddInParameter("@agent", System.Data.SqlDbType.VarChar, 150)


                'Dim productsTable As String = "Products"

                ' Retrieve the initial data
                'db.LoadDataSet(dbCommandWrapper, productsDataSet, productsTable)

            End If

        End Sub

        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            'CheckBox1.Text = Request.Form("myHiddenField")
        End Sub
    End Class

    Monday, October 24, 2005 5:19 AM

All replies

  • User-29418745 posted
    figured it out.
    Monday, October 24, 2005 8:51 AM
  • User192178519 posted
    well...can you post what you discovered??
    Saturday, November 19, 2005 12:55 AM
  • User192178519 posted

    ...i had a similar issue last nite. tho in my case, it was because the variable i was attempting to pass into the sql param was invalid. i would take a stab and say that, in your above code, "strEmail" is not a valid string.

    Saturday, November 19, 2005 12:48 PM
  • User-29418745 posted
    yeah it was something like passing in the wrong data type

    a real dumbass thing that really did require a post to the forum. :/

    Thursday, November 24, 2005 9:05 AM