我在查询中遇到错误" '#'附近的语法错误不正确如何解决它
代码:
cmd = new SqlCommand("SELECT
(invoiceNo) as [Invoice No],
(InvoiceDate) as [Invoice Date],
(Sales.CustomerID) as [Customer ID],
(CustomerName) as [Customer Name],
(GrandTotal) as [Grand Total],
(TotalPayment) as [Total Payment],
(PaymentDue) as [Payment Due]
from Sales,Customer
where
Sales.CustomerID=Customer.CustomerID
and
InvoiceDate between #" + DateTimePicker2.Text + "# And #" + DateTimePicker1.Text + "# and PaymentDue > 0
order by
InvoiceDate desc", con);
答案 0 :(得分:3)
如果您使用TSQL
,我认为您应该将date
作为字符串传递。但是,我不确定您是否需要任何时间部分,您可能需要修改tostring
cmd = new SqlCommand("SELECT
(invoiceNo) as [Invoice No],
(InvoiceDate) as [Invoice Date],
(Sales.CustomerID) as [Customer ID],
(CustomerName) as [Customer Name],
(GrandTotal) as [Grand Total],
(TotalPayment) as [Total Payment],
(PaymentDue) as [Payment Due]
from Sales,Customer
where
Sales.CustomerID=Customer.CustomerID
and
InvoiceDate between '" + DateTimePicker2.Value.ToString("yyyyMMdd") + "'
And '" + DateTimePicker1.Value.ToString("yyyyMMdd") + "' and PaymentDue > 0
order by
InvoiceDate desc", con);