error on simple query filter statement onClick event

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
 
N

Natty Gur

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
 
N

Natty Gur

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
 
D

DC Gringo

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
 
N

Natty Gur

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top