error on simple query filter statement onClick event

  • Thread starter Thread starter DC Gringo
  • Start date Start date
D

DC Gringo

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
 
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
 
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
 
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
 
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
 
Back
Top