DefaultView.RowFilter filter by date

0

Good afternoon, I'm filling a GridView, but when I'm going to perform the filter, it tells me the following error: "Object reference not set to an instance of an object." The field I'm trying to filter, expiration, is of type date, and I use SQL. I have tried in many ways, with # between dates, setting, but without the same error.

I tried this way:

 ds.Tables["cantas_apagar"].DefaultView.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "vencimento >= # {0} #", txtDataInicial.Text) + "and" + String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "vencimento <= # {0} #", txtDataInicial.Text);
                    GridView1.DataBind();

So:

 ds.Tables["cantas_apagar"].DefaultView.RowFilter = "(vencimento >= #" + txtDataInicial.Text + " # and vencimento <= #" + txtDataFinal.Text + "#)";
                    GridView1.DataBind();

If anyone has any ideas, thank you. Thank you.

    
asked by anonymous 12.04.2017 / 21:00

1 answer

0

I was able to solve the problem, it was not actually on the dates, but because the grid was not loading when I was going to run the filter, I put it to load before calling the method on the search button, and it worked perfectly.     

12.04.2017 / 22:00