Sign in | Join
Last post 06-07-2009 5:48 PM by Naom. 8 replies.
Sort Posts: Oldest to newest Newest to oldest
cmdSelect = New SqlCommand("SELECT most, least FROM Test WHERE QuestNo ='" + q1Lbl.Text + "'", conMyData)
The "most" and "least" are variables. I would like to know whether can i use the variables in the sql command as above??
Above is a wrong way of passing data to sql query use parameters
http://aspsnippets.com/post/Parameterized-Queries-ADONet.aspx
Download the source and use it
If most, least are column names in "Test" table then you can use the query as you mentioned:
Hi,
No, you can't use C# variable in SQL Command like this. Can you please let me know that why you want to use these variables in SQL Command? So that i might be able to suggest you some alternative.
Thank You
Muhammad Akhtar Shiekh
Im getting a selected value from a radio button list(RBL) and storing that value into a variable. The value that ill be getting from the RBL are M1 or M2 or M3 or M4, which are also column names in the Test table. Kindly advice me on other alternatives.
Okey, Go it.
All you need is to contact the values of these variable in SQL Query , like following
SqlCommand("SELECT " +most + ", " +least + " FROM Test WHERE QuestNo ='" + q1Lbl.Text + "'", conMyData )
Thanks
cypher_jy: Im getting a selected value from a radio button list(RBL) and storing that value into a variable. The value that ill be getting from the RBL are M1 or M2 or M3 or M4, which are also column names in the Test table. Kindly advice me on other alternatives.
Did you refer the article lin I gave you ?? Tell me what problem you are facing?
May I ask what is the point of this query?
The "most" and "least" are variables.
That's fine, but are they numeric values or column names?
Looks like they were column names.