Solved

Parameter issue with DateTime

Posted on 2009-05-07
5
337 Views
Last Modified: 2012-05-06
I am getting an error when trying to insert the datetime into an sql table. There error message I am getting is
Failed to convert parameter value from a String to a DateTime.
any help would be appreciated.
db.AddInParameter(dbCommand, "@datecreated", DbType.DateTime, ("MM/dd/yyyy"));

Open in new window

0
Comment
Question by:mockweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24327233
Off the bat, I would say that ("MM/dd/yyyy") is causing the issue. But to be safe--what object type is db?
0
 
LVL 13

Expert Comment

by:iHadi
ID: 24327372
What Db engine are you using (Sql Server, Oracle, Mysql, Access, ..)

If Mysql the date should be in the following format: "yyyy-mm-dd"
0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24327549
What is the datetime value you are passing to the DB?
0
 

Author Comment

by:mockweb
ID: 24327810
Database db = DatabaseFactory.CreateDatabase("SQLConnectionString");
                string sqlCommand = "stp_librarysuggestionInsertNew";
                DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24328001
Did you try changing "(MM/dd/yyy)" to your variable name like:
DateTime somdDate = DateTime.Now;  // example datetime variable
 
db.AddInParameter(dbCommand, "@datecreated", DbType.DateTime, someDate);

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question