This is simple C# method to first check the null dataset and then check tables exist in dataset and then check for rows exist in tables you need now to check for columns because if rows exist column will also exist.
Now you can use the C# tostring function to convert dataset values to string format and store in string variable.
This is one line check for all values in dataset. Please let me know if you face any problem.
- private void CheckDataSetNull(DataSet oDS)
- {
- if (oDS != null && oDS.Tables.Count > 0 && oDS.Tables[0].Rows.Count > 0)
- {
- //Fetch the values from rows and coloumns
- string strName = oDS.Tables[0].Rows[0][0].ToString();
- }
- }
you can also use Column name instead of column number while fetching the values, Please note that this check is for row 1 only for specific row you can use your customize check as per your requirement.
- private void CheckDataSetNull(DataSet oDS)
- {
- if (oDS != null && oDS.Tables.Count > 0 && oDS.Tables[0].Rows.Count > 0)
- {
- //Fetch the values from rows and coloumns
- string strName = oDS.Tables[0].Rows[0]["Column_Name"].ToString();
- }
- }
0 comments:
Post a Comment