Click here to Skip to main content
13,298,965 members (41,743 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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;
Posted 24-Nov-12 21:45pm
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
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;

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.
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 |
Web02 | 2.8.171207.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2017
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