Failed to convert parameter value from a SqlParameter to a DateTime.

M

mikejacobz

Hi, I am using the Enterprise Application Blocks (Data Access
Application Block 2005) and all I want to do is pass in a date as a
parameter to a Stored procedure.

e.g

[Begin C# code]

private void testMe(DateTime startDate)
{
// Create a database object
Database db =
DatabaseFactory.CreateDatabase("ConnectionString");

// Get back a DataReader
IDataReader _reader = db.ExecuteReader("spMyStoredProcedure",
new SqlParameter("@queryDate", startDate));

}
[End code]

Where @queryDate is a parameter of type DateTime in my Stored
Procedure.

When I try to run the above code I get the following error

"Failed to convert parameter value from a SqlParameter to a DateTime."

?? Any help greatly appreciated
Regards
Mike
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Use this code:

Sql SqlParameter param = new SqlParameter("@queryDate", SqlDbType.DateTime)
param.Value = startDate;
IDataReader _reader = db.ExecuteReader("spMyStoredProcedure", param);



--
Ignacio Machin
machin AT laceupsolutions com


| Hi, I am using the Enterprise Application Blocks (Data Access
| Application Block 2005) and all I want to do is pass in a date as a
| parameter to a Stored procedure.
|
| e.g
|
| [Begin C# code]
|
| private void testMe(DateTime startDate)
| {
| // Create a database object
| Database db =
| DatabaseFactory.CreateDatabase("ConnectionString");
|
| // Get back a DataReader
| IDataReader _reader = db.ExecuteReader("spMyStoredProcedure",
| new SqlParameter("@queryDate", startDate));
|
| }
| [End code]
|
| Where @queryDate is a parameter of type DateTime in my Stored
| Procedure.
|
| When I try to run the above code I get the following error
|
| "Failed to convert parameter value from a SqlParameter to a DateTime."
|
| ?? Any help greatly appreciated
| Regards
| Mike
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top