• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Parameter issue with DateTime

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
mockweb
Asked:
mockweb
1 Solution
 
käµfm³d 👽Commented:
Off the bat, I would say that ("MM/dd/yyyy") is causing the issue. But to be safe--what object type is db?
0
 
iHadiCommented:
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
 
HarryNSCommented:
What is the datetime value you are passing to the DB?
0
 
mockwebAuthor Commented:
Database db = DatabaseFactory.CreateDatabase("SQLConnectionString");
                string sqlCommand = "stp_librarysuggestionInsertNew";
                DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
0
 
käµfm³d 👽Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now