Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing the error " the dataset in the objectdatasource does not contain any tables" and i have no idea what is causing this problem.

Below is an extract of my codes used to retrieve the second row from the database table:
C#
public DataSet GetConfirmedAdv2(int categoryID)
      {
          SqlConnection conn;
          StringBuilder sql;
          SqlDataAdapter da;
          DataSet confirmed;

          conn = dbConn.GetConnection();
          confirmed = new DataSet();
          sql = new StringBuilder();
          sql.AppendLine("SELECT a.imageID, a.categoryID ");
          sql.AppendLine("FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY PaymentID) AS RowNo FROM WP_advConfirmed) AS a ");
          sql.AppendLine("WHERE RowNo = 2");
          sql.AppendLine("INNER JOIN WP_advCategory AS b ");
          sql.AppendLine("ON a.categoryID = b.categoryID ");
          sql.AppendLine("WHERE a.categoryID = @categoryID ");

          //sql.AppendLine("AND a.companyID = @companyID");


          try
          {
              conn.Open();
              da = new SqlDataAdapter(sql.ToString(), conn);
              da.SelectCommand.Parameters.AddWithValue("@categoryID", categoryID);
              //da.SelectCommand.Parameters.AddWithValue("@companyID", companyID);
              da.Fill(confirmed);
          }
          catch (Exception ex)
          {
              errMsg = ex.Message;
          }
          finally
          {
              conn.Close();
          }

          return confirmed;
      }

After i bind this method to my objectdatasource and run the page, it shows me the error. Is there something wrong with my SELECT statement that might be causing this?

i tried using the Query string builder and is able to retrieve what i want. but when i copy over to the DAL, it does not work?

Any help will be greatly appreciated.
Posted
Updated 29-Jun-13 6:47am
v2
Comments
Aravindba 29-Jun-13 12:00pm    
u can use break point and check each line,then only u get which line u get error,if query is wrong,u can check with sql and fix in this code.
Mike Meinz 29-Jun-13 12:57pm    
You could paste your SQL SELECT statement into a SQL Server Management Studio query window to be sure that it works the way you expect. I am concerned about your dependence on a particular row being the second row in the subquery of WP_advConfirmed. The location of specific rows in a table or result set is usually non-deterministic.

1 solution

SQL
SELECT a.imageID, a.categoryID
            FROM (SELECT * FROM
            (SELECT *, ROW_NUMBER() OVER(ORDER BY PaymentID) AS RowNo FROM WP_advConfirmed) AS c WHERE c.ROWNo=2) AS a
            INNER JOIN WP_advCategory AS b
            ON a.categoryID = b.categoryID
            WHERE a.categoryID = @categoryID



Try this query. Actually the problem is in this line "sql.AppendLine("WHERE RowNo = 2");"
You are trying to get the value of "RowNo" in the same select statement's where clause, where it is being generated .The value is not available at the given point.
 
Share this answer
 
v2
Comments
Jerrell77 30-Jun-13 2:49am    
thank you so much!

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