0

I have a web based project using VB 2010 that gets data from sql 2005 server and populates a gridview which was dropped onto the web page from the toolbox.

My problem is i need to use a variable in the VB code and have searched and read hundreds of solutions but none work.

variables are dist and users, so if i enter 200m for dist and John for users then it works.

Here is the VB code which does not work using variables

SqlDataSource1.SelectCommand = "SELECT event, athname, D_ate, TIME1 FROM TableName

WHERE ( event='&dist&') And (athname = '&users&')"


I have tried different formatting characters for the variable ie @ ? etc.


This does work using literals

SqlDataSource1.SelectCommand = "SELECT event, athname, D_ate, TIME1 FROM TableName

WHERE ( event='200m') And (athname = 'John')"


I am totally stuck any help would be appreciated

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by aspproject
0

Maybe you are forgetting double quotes on both side of the variable:

SqlDataSource1.SelectCommand = SELECT event, athname, D_ate, TIME1 FROM TableName WHERE event='" & dist & "' AND athname = '" & users & "'"

Edited by Mitja Bonca: n/a

0

I don't know if you got it solved yet taxmybrain, but if you are following Mitja's suggestion you would also need a " before Select event

Thus making it:

SqlDataSource1.SelectCommand = "SELECT event, athname, D_ate, TIME1 FROM TableName WHERE event='" & dist & "' AND athname = '" & users & "'"

This assumes dist and users are your variables that have information that you would like to pass into sql.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.