मैं इस त्रुटि को कैसे हल कर सकता हूं?
चरित्र स्ट्रिंग से दिनांक और / या समय परिवर्तित करते समय रूपांतरण विफल रहा
मेरा SQL कोड:
SELECT
RTRIM(invoiceNo) as [Order No.],
RTRIM(InvoiceDate) as [Order Date],
RTRIM(SubTotal) as [SubTotal],
RTRIM(VATPer) as [Vat+ST %],
RTRIM(VATAmount) as [VAT+ST Amount],
RTRIM(DiscountPer) as [Discount %],
RTRIM(DiscountAmount) as [Discount Amount],
RTRIM(GrandTotal) as [Grand Total],
RTRIM(TotalPayment) as [Total Payment],
RTRIM(PaymentDue) as [Payment Due]
FROM
Invoice_Info
WHERE
InvoiceDate BETWEEN @d1 AND @d2
ORDER BY
InvoiceDate desc
और मैं इसे एक का उपयोग करके कहता हूं SqlCommand
C # से, इन मापदंडों को जोड़ना:
cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date;
cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateTo.Value.Date;
उत्तर:
जवाब के लिए 0 № 1मुझे लगता है कि आपको मूल्यों से ".डेट" को निकालना होगा, क्योंकि DateTimePicker.Value.Date क्षेत्र का केवल दिनांक भाग लौटा रहा है।
इसके अलावा आप मापदंडों को निम्न में बदल सकते हैं:
cmd.Parameters.Add("@d1", SqlDbType.DateTime).Value = dtpInvoiceDateFrom.Value;
cmd.Parameters.Add("@d2", SqlDbType.DateTime).Value = dtpInvoiceDateTo.Value;