Problem in DataSet
-
hi. Please see the following code. HistoryData is also a dataset..
string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"
Dataset dsData = HistoryData;
DataSet dsNew = new DataSet();DataTable dt = dsData.Tables[0];
DataRow dr = dt.Select(strExpression);
in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..
-
hi. Please see the following code. HistoryData is also a dataset..
string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"
Dataset dsData = HistoryData;
DataSet dsNew = new DataSet();DataTable dt = dsData.Tables[0];
DataRow dr = dt.Select(strExpression);
in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..
Hi, first of all the statement: DataRow dr = dt.Select(strExpression); will return the array of rows not a single row. So it will be DataRow[] dr = dt.Select(strExpression); After this you can traverse in the DataRow using Foreach and then can add the same in the new table having same columns(structure) foreach (DataRow dr in dt.Select(strExpression)) { DataRow drRow = newtable.NewRow(); // newtable having same structure as of the main table dt drRow["Column1"] = dr["Column1"].ToString(); drRow["Column2"] = dr["Column2"].ToString(); drRow["Column3"] = dr["Column3"].ToString(); ... drRow["Columnn"] = dr["Columnn"].ToString(); drRow.Rows.Add(drRow); newtable.AcceptChanges(); } This way you can get a new table having required rows. Regards, Kaushal Arora
-
hi. Please see the following code. HistoryData is also a dataset..
string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"
Dataset dsData = HistoryData;
DataSet dsNew = new DataSet();DataTable dt = dsData.Tables[0];
DataRow dr = dt.Select(strExpression);
in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..
I think better to use DataView to create new table instead looping through all filtered rows and add them to datatable i am suggesting following [code] DataView dva1=new DataView(dataTable or dataSet); DataTable dt=dva1.toTable(filterString); [/code]
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
I think better to use DataView to create new table instead looping through all filtered rows and add them to datatable i am suggesting following [code] DataView dva1=new DataView(dataTable or dataSet); DataTable dt=dva1.toTable(filterString); [/code]
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
I didnt find any option in which i can give the filterstring in the arguments. Kindly elaborate the answer in detail. If you have any sample code then share.