System.ArgumentException on filterClause.

nsabarisri6

New member
Joined
Dec 18, 2012
Messages
4
Programming Experience
1-3
Hi


My Requirement:

Get the selected Month as '1','2',...'10','11' , etc from the list box. Query the dataSource for PurchaseDate in the month and display the resultant set in the table.

I have my access table , with column PurchaseDate, in which the dates are like '1/10/2012', '11/1/2012', in the format 'mm/dd/yyyy';

in the below code, myDateFormat is mm/dd/yyyy , will it take the value 1/10/2012 and parse it correctly??
Is this the cause for my error as below?


I am getting the following exception after using filter clause.

Dim myDateFormat As String = "mm/dd/yyyy"
Dim filterClause As String = String.Format("PurchaseDate >= '{0}' and PurchaseDate <= '{1}'",
New DateTime(Now.Year, CInt(month)).ToString(myDateFormat),
New DateTime(Now.Year, CInt(month)).AddMonths(1).AddDays(-1).ToString(myDateFormat))

dv1 = New DataView(ds2.Tables(0), filterClause, "BillNo", DataViewRowState.CurrentRows)

Exception:
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll
The thread 'vshost.RunParkingWindow' (0x714) has exited with code 0 (0x0).


Kindly help me in this regard.


Thanks,
Sabarisri. N

 

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

The only thing I can see that is wrong is the declaration of your DateFormat variable. You have currently got:-

VB.NET:
Dim myDateFormat As String = "mm/dd/yyyy"

and it should be:-

VB.NET:
Dim myDateFormat As String = "MM/dd/yyyy"

Notice the capital M's in the month declaration. This is crucial for date formats.

Hope that helps.

Cheers,

Ian
 
Top Bottom