C# .NET - {"Cannot find table 0."} - Asked By SVK N on 12-Jun-12 10:44 PM

 SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "employee");
            conn.Close();
            return ds.Tables[0];



{"Cannot find table 0."}


"   at System.Data.DataTableCollection.get_Item(Int32 index)\r\n   at 
TSN ... replied to SVK N on 12-Jun-12 11:51 PM

HI…

 

Change the below line of Code and everything works fine then

 

return ds.Tables[0];

to

return ds.Tables[“employee”];

 

S K replied to SVK N on 13-Jun-12 12:25 AM
Check your cmd commad object set correct command text or stored proc that return any table if that return table than you can get table by using ds either ds.Tables[0] or ds.Tables["employee"] both are return the correct if in select statement of employee table are first in your stored porc but when you specify the table name than no problem.
Jitendra Faye replied to SVK N on 13-Jun-12 12:40 AM
Change your code like this-

SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "employee");
            conn.Close();

if(ds!=null)
 {
            return ds.Tables[0];
  }
else
{
  return null;
}


Try this and let me know.