Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can i sove th error :Cannot find table 0.? what could be the reason?
getting error in this code,

DataSet xxx= new DataSet();
dt = xx.Tables[0].DefaultView.ToTable(true, "Fieldname");

Please help me.

A big thanks in advance
Posted

try this:
C#
DataSet dataSetObject = new DataSet();
sqlDataAdapterObject.Fill(dataSetObject);
DataTable dataTableObject = dataSetObject.Tables[0].DefaultView.ToTable(true, "Fieldname");
 
Share this answer
 
The place where you are binding your dataset, put a break point and see. Your dataset is empty, that's why it cannot find table 0.
For example if you are using a procedure to get the data and that you are binding to the dataset, then your procedure is not returning any row.
 
Share this answer
 
The reason could be that you wrote

xx.Tables["0"]


instead of

xx.Tables[0]


Difficult to say more, as the code you provided would not even compile.
 
Share this answer
 
Your DataSet is "xxx" and you are using "xx" in the second line of code.
 
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