Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL Reports
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
Posted 16-Sep-12 2:45am
Edited 16-Sep-12 4:49am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
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.
  Permalink  
Comments
losmac at 16-Sep-12 11:56am
   
Good answer, +5!
Sandeep Mewara at 16-Sep-12 11:58am
   
Thanks Mac!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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) 
 
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)
  Permalink  
Comments
FlyingBird_ at 28-Sep-12 8:03am
   
my 5+
Maciej Los at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 487
1 CPallini 345
2 OriginalGriff 240
3 George Jonsson 159
4 Abdul Samad KP 145
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100