This is working for me just fine. With if checks if dataset is empty or not. If so, return null value. But is the check of dataset right way or should i do some other way?
da2 = new SqlDataAdapter("SELECT project_id FROM project WHERE _small_project_id = '" + cb_small_project.SelectedValue + "' ORDER BY NEWID()", conn);
ds2 = new DataSet();
da2.Fill(ds2);
DataRow[] rowProject = dt2.Select();
if (ds2.Tables[0].Rows.Count == 0)
cmd.Parameters["@_project_id"].Value = guidNull;
else
cmd.Parameters["@_project_id"].Value = rowProject[0]["project_id"];
If the dataset exists but has zero observations, then the dataset is empty. You can check the number of observations with the COUNT function, the Dictionary Tables, the Descriptor Portion of a dataset, or with a macro function.
empty attribute checks if the dataframe is empty or not. It returns True if the dataframe is empty else it returns False in Python.
Rows. Count != 0);This will return true if there are any rows in any of the tables. It will return false if there are no tables or no rows.
This Worked for me.... and won't give exception....
foreach (DataTable table in ds.Tables)
if (table.Rows.Count != 0)
table.Dispose();
In my opinion the 'right' way is to check both:
ds2.Tables.Count
ds2.Tables[0].Rows.Count
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With