Wednesday, 14 August 2013

Is datatable empty

Is datatable empty

I had a a function like this
con.Open();
int k = 1;
OleDbCommand cmd1 = new OleDbCommand("select MAX (CUT_ID) from
CUTORDER_MASTER ", con);
OleDbDataReader rdr = cmd1.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rdr);
if (dt != null)
{
if (int.Parse(dt.Rows[0][0].ToString()) != 0)
{
k = int.Parse(dt.Rows[0][0].ToString()) + 1;
}
}
My issue is if there is no value retrieved by query the data table is
returning a cell max(cutid) without any value. therefore it skips the null
check and if O check and code reaches k =
int.Parse(dt.Rows[0][0].ToString()) + 1;
causing Exception incorrect format
Is there any way to solve this issue and check whether the data table is
empty

No comments:

Post a Comment