c#从当前日期减去30天后出错?的WinForms [英] Error in c# subtracting 30 days from current date ? winforms
本文介绍了c#从当前日期减去30天后出错?的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从当前日期减去30天然后我过滤查询但我没有得到任何结果/输出为什么我的错误在这个代码上
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
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];
空表只显示我是否运行此代码。如果我将-30更改为-4,则从Access DB中获取一行。从4月1日到当前日期4月8日,如果我们给-3,-4,-5,-6,-7这个代码,但工作小错误是< &安培; > 中这个代码中只有=符号不起作用吗?
非常感谢。
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.
推荐答案
将您的查询从字符串连接更改为参数化查询 - 这将帮助您处理MS Access的奇数日期格式行为。
Change your query from string concatenation to a Parameterized Query - that will help you deal with the odd date format behavior of MS Access.
这篇关于c#从当前日期减去30天后出错?的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文