Reportviewer日期参数中的错误 [英] error in reportviewer date parameters

查看:82
本文介绍了Reportviewer日期参数中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在C#中将存储过程链接到reportviewer时,出现此错误:

When i linked my stored procedure to reportviewer in C# i get this error:

argument 1 cannot convert string to System.datetime
argument 2 cannot convert string to System.datetime


this.WaybillsTableAdapter.Fill(this.DataSet1.Waybills, textBox3.Text, textBox4.Text, textBox1.Text);


textbox3 parameter is stardate
textbox4 parameter is enddate


有人知道如何解决此问题吗?

这是我的存储过程:


anybody have a idea how to fix this?

This is my stored procedure:

create proc GenerateInvoice
@StartDate date ,
@EndDate date ,
@ReceiverName varchar(30) 

AS

SELECT         Waybills.SenderName, Waybills.SenderAddress, Waybills.SenderContact, Waybills.ReceiverName, Waybills.ReceiverAddress, 
                         Waybills.ReceiverContact, Waybills.UnitDescription, Waybills.UnitWeight, Waybills.DateReceived, Waybills.Payee, 
                          Payments.Amount, Payments.PaymentDate, Cycle.CycleNumber, Cycle.StartDate, Cycle.EndDate
FROM            Waybills CROSS JOIN
                         Payments CROSS JOIN
                         Cycle
WHERE Waybills.ReceiverName = @ReceiverName
AND (Waybills.DateReceived BETWEEN (@StartDate) AND (@EndDate))

go

推荐答案

textbox3参数为stardate
textbox4参数为结束日期

即使参数是最新的,但它们仍通过文本框文本传递.因此,它们只是字符串(即使是日期格式,也不是日期)

您需要将字符串转换为日期时间,然后传递给SP.请使用Convert.ToDateTime()DateTime.Parse().
试试:
textbox3 parameter is stardate
textbox4 parameter is enddate

Even though the parameters are of date, but they are being passed through a textbox text. Thus, they are mere strings (and not date even if it is of date format)

You need to convert the string into datetime and then pass on to SP. Use Convert.ToDateTime() or DateTime.Parse() for it.
Try:
this.WaybillsTableAdapter.Fill(this.DataSet1.Waybills, Convert.ToDateTime(textBox3.Text), Convert.ToDateTime(textBox4.Text), textBox1.Text);


顺便说一句,以上是一个快速修复.您应该首先检查文本,看看是否正确转换为DateTime.此外,也许您可​​以尝试使用datepicker控件代替日期字段的文本框.


BTW, above one is a quick fix. You should first check the text and see if correctly converted into DateTime. Further, may be you can try to use datepicker control instead of a textbox for date fields.


Sandeep Mewara的答案很好,我想请您注意SP.

Sandeep Mewara answer is good and i would like to turn your atention for your SP.

create proc GenerateInvoice
@StartDate date ,
@EndDate date ,
@ReceiverName varchar(30) 



据我所知,date输入参数仅适用于MS SQL Server2012.在其他(先前)版本中,您需要使用DateTime.有关更多信息,请访问: http://msdn.microsoft.com/en-us/library/ms186724.aspx [ ^ ]

where条件更易于理解:



As far as i know the date input parameter is only avalible for MS SQL Server 2012. In other (previous) versions, you need to use DateTime. More at: http://msdn.microsoft.com/en-us/library/ms186724.aspx[^]

The where condition is more readible for:

WHERE (Waybills.ReceiverName = @ReceiverName) AND (Waybills.DateReceived BETWEEN @StartDate AND @EndDate)


这篇关于Reportviewer日期参数中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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