How to Apply where Query on DataTable object in C# ASP.NET

Follow below code:-
                     DataTable dt = new DataTable();
                    dt = (DataTable)ViewState["Data"];
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Select("FeedbackTypeID =" + FeedbackTypeID + " and                                              FeedbackParamID=" + FeedbackParamID + "").First();
                        if (dr != null)
                        {
                            string data = dr["FeedbackGradeID"].ToString();
                        }
                    }


 DataTable is present in using System.Data Namespace 
 here I store ViewState Data into DataTable object.
 If dt object has data then Apply:

  DataRow dr = dt.Select("FeedbackTypeID =" + FeedbackTypeID + " and                                              FeedbackParamID=" + FeedbackParamID + "").First();

Here in dt.Select() contains the condition I am just showing the hint you have to use it with your data and query.




Post a Comment

0 Comments