Click here to Skip to main content
15,560,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, in my data access layer i have a method to return a particular field using WHERE clause.

I encountered an error : Dataset in object data source does not contain any tables

below is the code that results in the error message due to the WHERE clause :
public DataSet getImage(int imageID, String companyID)
        {
            SqlConnection conn;
            StringBuilder sql;
            SqlDataAdapter da;
            DataSet image;

            conn = dbConn.GetConnection();
            image = new DataSet();
            sql = new StringBuilder();
            sql.AppendLine("SELECT * FROM WP_advUploads");
            sql.AppendLine("WHERE imageID=@imageID");
            try
            {
                conn.Open();
                da = new SqlDataAdapter(sql.ToString(), conn);
                da.Fill(image);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }

            return image;
        }

if i remove the WHERE clause, it shows all the information in the database. i only want the one with the specific imageID.

Any one have solution to this?
Posted
Updated 17-Jun-13 7:29am
v2
Comments
Richard C Bishop 17-Jun-13 12:23pm    
Try putting a space between _advUploads and WHERE and where is "@imageID" value coming from? My guess is you want something like this:

sql.AppendLine("SELECT * FROM WP_advUploads ");
sql.AppendLine("WHERE imageID = " + imageID);
Jerrell77 17-Jun-13 13:16pm    
thank you so much! problem solved! btw what is the difference between @imageID and having a +imageID??
Richard C Bishop 17-Jun-13 13:59pm    
I went ahead and added it as the solution. The difference is that "@imageID" is not an object in the scope you are referencing it and "imageID" is the value passed into the method you are wanting to check for in your WHERE clause.
Zain -Ul- Arifeen 17-Jun-13 13:52pm    
try this code.....

sql.AppendLine("SELECT * FROM WP_advUploads");
sql.AppendLine("WHERE imageID='"+textbox1.Text+"'");
Richard C Bishop 17-Jun-13 14:08pm    
That is not a good suggestion nor is a TextBox involved. That leaves the OP susceptible to sql injection attackes which can destroy a database. Always use paramertized queries if your query values are coming from user input.

1 solution

Try putting a space between _advUploads and WHERE and where is "@imageID" value coming from? My guess is you want something like this:
sql.AppendLine("SELECT * FROM WP_advUploads ");
sql.AppendLine("WHERE imageID = " + imageID);
 
Share this answer
 

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



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