开发者

Determine if Tables[0] Exists

While executing the following statement to bind my database to my datagridview, I get this error:

Cannot find table 0.

How can I determine if Tables[0] exists prior to executing this statement? :

myDataView = myDataSet.Tables[0].DefaultView;

I am using SQL Server 2005 Ex开发者_C百科press.


Try the following

if (myDataSet.Tables.Count > 0 ) { 
  ...
}


Try this:

if (myDataSet.Tables != null && myDataSet.Tables.Count > 0)
{
   // do stuff
}


Does the DataSet have more than one table? If not, then you should be able to just check if the DataSet itself is null. This is generally the syntax that I'll do...

DataSet ds = BLL.GetMyDataSet();

if (ds != null && ds.Tables[0].Rows.Count > 0) {
  // TODO
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜