DataView Filter Not working

T

Tim

I am using the following code to filter a DataView and then put the
dataview back into a DataSet. I've verified that strFilter contains
683 values.

The dataview initially has 1306 records before the filter. However,
the resulting dataset that comes out has all 1306 rows.

How is this possible since I'm filtering on 683 unique values?

I'd appreciate any help

-Tim

//create a dataview for the dataset
//DataTable oDT = oDS.Tables["Results"];
DataView oDV = new DataView(oDS.Tables["Results"]);

DataTable oDT = new DataTable();
try
{
if(strFilter != "")
{
//filter the dataview with the previous work ids

oDV.RowFilter = "WorkID IN (" + strFilter + ")";
}
}
catch(Exception err)
{
Response.Write("Error: " + err.Message.ToString());
}

//Convert the DataView back to a DataSet
oDT = oDV.Table.Copy();
oDS = new DataSet(oDV.Table.TableName);
oDS.Tables.Add(oDT);
 
W

William Ryan

You are copying the source table and adding the source table to the new
dataset. Remember that a Datatview is like a virtual table because it's
based on a table.

If you iteratively went through the dataview and added it to a table row by
row, then added the table to the dataset, you'll have only what was
filtered. But copying the whole table in is going to give you back the
whole table.

In most instances though, having the datatable in a dataset should
suffice...copying it to another one, in many cases probably isn't necessary.

HTH,

Bill
 
Joined
Apr 8, 2008
Messages
1
Reaction score
0
filtering data in dataview

Hi all,
I am new to group. Here is my question:
I have an xml file having nodes like below:
<Datetime>

<
oldvalue>Alerts enabled</oldvalue>

<
newvalue>Alerts disabled</newvalue>

<
username>Administrator</username>

<
key>HardDiskDriveFreeSpaceCheck</key>

<
time1>2008.04.09</time1>

</
Datetime>

i am assiging this to a dataset. and i have to filter the "time1" existed between given dates.
here is my code:
DataSet ds = new DataSet();

ds.ReadXml(
"configurations.xml");//the above node existed in configuraitions XML file

DataView dv = ds.Tables[0].DefaultView;

string filter = "convert(datetime, time1) > convert(datetime, '" + startdate.ToString("yyyy/MM/dd") + "') AND convert(datetime, time1) < convert(datetime, '" + enddate.ToString("yyyy/MM/dd") + "')";//Start date and end date will be reading from UI text boxes.

dv.RowFilter = filter;
but time1 is treating as string and i could not able to convert that as date time. How can I convert that string to datetime.

Thanks in advance
Sivakumar V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top