error on simple query filter statement onClick event

Discussion in 'ASP .Net' started by DC Gringo, Mar 3, 2004.

  1. DC Gringo

    DC Gringo Guest

    I'm getting the following error when running and if-then upon submitting a
    dropdownlist value. HELP?!

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

    Sub RunReport_OnClick(sender As Object, e As System.EventArgs)

    If ddlCommunities.SelectedItem.Value <> 0 Then
    _sqlStmt = _sqlStmt & " AND tblSurvey1.clnGUID =
    '"+ddlCommunities.SelectedItem.Value+"'"
    End if

    BindData()
    End Sub

    --
    _____
    DC G
    DC Gringo, Mar 3, 2004
    #1
    1. Advertising

  2. DC Gringo

    Natty Gur Guest

    Hi,

    1) It looks like the dropdownlist value cause a problem in the DB. This
    error usually comes up when you send incorrect values.

    2) VB.NET introduce += operator for strings:

    _sqlStmt += " AND tblSurvey1.clnGUID =
    '"+ddlCommunities.SelectedItem.Value+"'"

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Mar 4, 2004
    #2
    1. Advertising

  3. DC Gringo

    Natty Gur Guest

    Hi,

    1) It looks like the dropdownlist value cause a problem in the DB. This
    error usually comes up when you send incorrect values.

    2) VB.NET introduce += operator for strings:

    _sqlStmt += " AND tblSurvey1.clnGUID =
    '"+ddlCommunities.SelectedItem.Value+"'"

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Mar 4, 2004
    #3
  4. DC Gringo

    DC Gringo Guest

    Thank you, Natty...In fact, this does work...it just fails when I put in any
    of these IF Then statements

    Sub RunReport_OnClick(sender As Object, e As System.EventArgs)
    If ddlCommunities.SelectedItem.Value += 0 Then

    _sqlStmt

    Else
    _sqlStmt += " AND tblSurvey1.clnGUID =
    '"+ddlCommunities.SelectedItem.Value+"'"

    End if


    BindData()
    End Sub


    HERE'S THE REST OF MY RELEVANT CODE:



    Protected _sqlStmt As String = _
    "SELECT col FROM table"

    Sub Page_Load(Source As Object, E As EventArgs)
    If Not Page.IsPostBack Then
    BindData()
    End If
    End Sub

    Sub BindData()
    Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"

    Dim myDataSet1 As New DataSet
    Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
    myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
    DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")

    Dim myDataSet5 As New DataSet
    Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
    myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
    ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
    ddlCommunities.DataMember = "CommunitiesT2"
    ddlCommunities.DataTextField = "clnName"
    ddlCommunities.DataValueField = "clnGUID"

    DataGrid2.DataBind()

    ddlCommunities.DataBind()
    ddlCommunities.Items.Insert(0,New ListItem("--ALL","0"))

    End Sub



    "Natty Gur" <> wrote in message
    news:...
    > Hi,
    >
    > 1) It looks like the dropdownlist value cause a problem in the DB. This
    > error usually comes up when you send incorrect values.
    >
    > 2) VB.NET introduce += operator for strings:
    >
    > _sqlStmt += " AND tblSurvey1.clnGUID =
    > '"+ddlCommunities.SelectedItem.Value+"'"
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    DC Gringo, Mar 4, 2004
    #4
  5. DC Gringo

    Natty Gur Guest

    Hi,

    And I forgot that the If excretion return bool value and your code
    return string excretion. You should change it.

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Mar 4, 2004
    #5
  6. DC Gringo

    Natty Gur Guest

    VB, VB ... If you use C# you will get compilation error (or maybe you
    get it on VB)

    The error is due to the fact that ddlCommunities.SelectedItem.Value
    return string and you tring to operate an operation with numeric left
    side and string right side:

    ddlCommunities.SelectedItem.Value += 0


    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Mar 4, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JerryG
    Replies:
    0
    Views:
    422
    JerryG
    Dec 20, 2005
  2. zax75
    Replies:
    1
    Views:
    1,094
  3. bob
    Replies:
    3
    Views:
    183
  4. Joshua Beall
    Replies:
    2
    Views:
    72
    John Doe
    Feb 7, 2005
  5. Replies:
    2
    Views:
    253
Loading...

Share This Page