Missy
Missy

Reputation: 1368

How to use Table Adapter Fill with SQL Server stored procedure with two parameters

I have a stored procedure with two parameters - beginDate and endDate. I created a table adapter and it looks like it expects two parameters because on the designer screen it shows @beginDate, @endDate.

When I go to fill it:

DateTime beginDate = new DateTime(2016, 5, 1);
DateTime endDate = new DateTime(2016, 5, 31);

this.getDailySalesTableAdapter.Fill(myDataSet.getDailySales, beginDate, endDate);

I get an error that argument 3 must be passed with the 'ref' keyword. When I add the ref keyword, I get the error that argument 3 cannot convert from ref System.DateTime to System.DateTime? I am using SQL Server.

Upvotes: 0

Views: 630

Answers (2)

Nouman Bhatti
Nouman Bhatti

Reputation: 1421

This is a nice article to understand the nullable types and yes @wablab mentioned correctly you need to declare you datetime variable as nullable datetime

Upvotes: 1

wablab
wablab

Reputation: 1733

Sounds like "Argument 3" is expected to be a nullable DateTime. Change your declaration of endDate to:

DateTime? endDate = new DateTime(2016, 5, 31);

Upvotes: 1

Related Questions