“从字符串转换日期和/或时间时转换失败” ?我能做什么 ? [英] "Conversion Failed When Converting Date And/Or Time From Character String" ? What Can I Do ?

查看:124
本文介绍了“从字符串转换日期和/或时间时转换失败” ?我能做什么 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

con = new SqlConnection(cs.DBConn);
con.Open();
cmd = new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],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],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and InvoiceDate between @d1 and @d2 order by InvoiceDate desc", con);
cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date.ToShortDateString();
cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateTo.Value.Date.ToShortDateString();
SqlDataAdapter myDA = new SqlDataAdapter(cmd);
POS_DBDataSet myDataSet = new POS_DBDataSet(); 
myDA.Fill(myDataSet, "Invoice_Info");

推荐答案

cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date.ToShortDateString();



为什么要将日期转换为字符串?


Why are you converting the date to a string?


数据库中的字段类型是nc​​har(30)...所以我在任何过程之前转换它
the field type in database is nchar(30)...so i am converting it before any process


这篇关于“从字符串转换日期和/或时间时转换失败” ?我能做什么 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆