473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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

Jan 16 '07 #1
2 12591
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
<mi********@gmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.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
|
Jan 16 '07 #2
Thanks!
Regards
Mike
Ignacio Machin ( .NET/ C# MVP ) wrote:
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
<mi********@gmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.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
|
Jan 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Narshe | last post by:
If I use this simple code SqlParameter param = new SqlParameter( "@param", SqlDbType.DateTime ); param.Value = System.DateTime.Now; param.Value is "11/2/2005" rather than "11/2/2005 10:42:15...
0
by: Davide | last post by:
Hi We have a stored procedure for inserting data into a table and another for Updating that table. For the Insert SP we use a LastModifiedDateTime output parameter and for the Update SP we...
3
by: juststarter | last post by:
Hello all, I am executing a stored procedure (on an SQL Server) using ODBC but i can't get the output parameter's value on the client. The stored proc has 3 parameters ,2 of them are input and 1...
0
by: Chris Crowe [MVP 1997 -> 2006] | last post by:
I am having major problems using GetStoredProcCommand and using Parameters in the same function call in the latest builds of the Enterprise Library Data. The error I get is : Failed to...
2
by: glenn | last post by:
Hi folks, I guess this question has to do with formatting dates. Seems like it should be a no brainer but have spent too much time hunting so I am posting the forum. I have a function that...
0
by: weird0 | last post by:
Here is the code for executing stored procedure ExecuteSP() , and object that sets all its parameters in other functions and the stored procedure. I think it has something to do with db datatypes...
1
by: Elmo Watson | last post by:
The date format in the 'weekending' textbox is 5/5/2007 Here's what I've got: With cmd.Parameters ..Add(New SqlParameter("@SQLweekending", SqlDbType.DateTime, weekending.Text)) the error...
3
by: preeti13 | last post by:
i have a store procedure need to get the date from the data base help me please with this. i know something missing in the code right here: da.SelectCommand.Parameters.Add(new...
4
by: sweatha | last post by:
Hi In sql server 2005 I have a column as GraduationYear Decimal(4,0). In asp.net I used the coding for that as SqlParameter GraduationYear = new SqlParameter("@GraduationYear",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.