Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pls Help me in Finding the error.
Thanks in advance

C#
string qry = "select * from " + tableName + "where campaignid= " + campaignid;
           ds = MySqlHelper.ExecuteDataset(GetConnectionString(), qry);
           if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
           {
               Control.DataSource = ds;
               Control.DataTextField = lstText;
               Control.DataValueField = lstValue;
               Control.DataBind();
           }
Posted
Comments
pankajgarg1986 25-Nov-12 3:04am    
it is solved and answer is:-
string qry = "select * from " + tableName + "where campaignid='" + campaignid + "'";

1 solution

The most likely reason is that your tablename does not end with a space - so it will get run together with the "where" to form a new name:
SQL
SELECT * FROM myTablewhere campaignid= 1

Try adding a space to your code:
C#
string qry = "select * from " + tableName + "where campaignid= " + campaignid;

Becomes
C#
string qry = "select * from " + tableName + " where campaignid= " + campaignid;


But it is not a good idea to do that anyway: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

BTW: It is also poor form to use SELECT * FROM - it may return data you don't want or need such as image data. It is much better practice to explicitly list the fields you want, in the order you want them.
 
Share this answer
 
Comments
pankajgarg1986 25-Nov-12 3:06am    
Thanks OriginalGriff ..
OriginalGriff 25-Nov-12 3:09am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900