How to filter DataView by RowFilter when using XML file as DataSource for DataGridView and filtering a date C#?

61 Views Asked by At

I searched a lot but i could find anything that helps.

I have a XML file and i want to make it DataSource for my DataGridView. Till now all is good. My element in the XML file is similar to this:

  <id>1</id>
  <name>First last name</name>
  <date>02072019</date>
  <incAtt>Yes</incAtt>

Edit1: Here is my DataSource:

//Globally defined these two
private DataSet dataSet;
private DataView dv;

//In Form1_Shown
dataSet = new DataSet();

using (var xmlFile = newStreamReader(@"C:\Users\sami_\Desktop\kyc_div_updates.xml", Encoding.GetEncoding("windows-1256")))
{

    dataSet.ReadXml(xmlFile);

    dv = dataSet.Tables[2].DefaultView;

    dv.Sort = "الفرع";

    dataGridView1.DataSource = dv;

    countL.Text = dataGridView1.Rows.Count + "Item(s)";

    SetColumns();
}

I want to filter the datagridview by RowFilter and get all elements that their date is from 01012019 to 01012020

I tried many ways and i put ## between my values but i always get String was not recognized as a valid DateTime. Part of my code is this:

"date=#" + dateEnterD.Value.ToString("ddMMyyyy") + "# and "

dateEnterD is DateTimePicker

Edit2: Here is the Trace of the error:

at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.Data.ConstNode..ctor(DataTable table, ValueType type, Object constant, Boolean fParseQuotes)
at System.Data.ConstNode..ctor(DataTable table, ValueType type, Object constant)
at System.Data.ExpressionParser.Parse()
at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)
at System.Data.DataView.set_RowFilter(String value)
at KYCUpdates.Form1.Search_Search(String key) in D:\Visual Studio 
2015\Projects\KYCUpdates\KYCUpdates\Form1.cs:line 120

Is there a way i can search elements between two dates or not in my case?

Thanks

0

There are 0 best solutions below