Click here to Skip to main content
12,634,422 members (27,218 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
Pls Help me in Finding the error.
Thanks in advance

 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 24-Nov-12 21:45pm
Comments
pankajgarg1986 25-Nov-12 3:04am
   
it is solved and answer is:-
string qry = "select * from " + tableName + "where campaignid='" + campaignid + "'";

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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:
SELECT * FROM myTablewhere campaignid= 1

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

Becomes
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.
  Permalink  
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


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100