Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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:
SQL
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
Posted
Updated 16-Sep-12 4:49am
v2

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:
C#
this.WaybillsTableAdapter.Fill(this.DataSet1.Waybills, Convert.ToDateTime(textBox3.Text), Convert.ToDateTime(textBox4.Text), textBox1.Text);

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.
 
Share this answer
 
Comments
Maciej Los 16-Sep-12 11:56am    
Good answer, +5!
Sandeep Mewara 16-Sep-12 11:58am    
Thanks Mac!
Sandeep Mewara answer is good and i would like to turn your atention for your SP.

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


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:
SQL
WHERE (Waybills.ReceiverName = @ReceiverName) AND (Waybills.DateReceived BETWEEN @StartDate AND @EndDate)
 
Share this answer
 
Comments
wings_ 28-Sep-12 8:03am    
my 5+
Maciej Los 28-Sep-12 12:54pm    
Thank you, FlyingBird ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900