Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to subtract 30 days from current date then i filter query but i didn't get any results/ output why whats my error on this code
C#
DateTime curdate = DateTime.Now;
curdate = curdate.AddDays(-30); // if i give -4 instead of -30 the query will bind data
DateTime curdate1 = DateTime.Now;

validateDept.InitializeConnection();
OleDbConnection connection = new OleDbConnection(validateDept.connetionString);
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT InvoiceId, InvoiceNumber, InvoiceDate, (Select CustomerId from Customer Where Customer.CustomerId=NewInvoice_1.CustomerName) AS CustomerId, (Select CustomerName from Customer where Customer.CustomerId = NewInvoice_1.CustomerName) AS CustomerName, DueDate, Tax, GrandTotal, CompanyId FROM NewInvoice_1 WHERE InvoiceDate >= '" + curdate + "' AND InvoiceDate <= '" + curdate1 + "' ", connection);
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet);
gridControl1.DataSource = sourceDataSet.Tables[0];

empty table only shows if i run this code. If i change -30 to -4 then it fetch one row from Access DB. From 1st april to current date 8th april if we give -3,-4,-5,-6, -7 this code but works small error is that "<" & ">" this only working "=" sign not working in this code ?

Thanks a lot.
Posted

1 solution

Change your query from string concatenation to a Parameterized Query - that will help you deal with the odd date format behavior of MS Access.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900