Solved

Parameter issue with DateTime

Posted on 2009-05-07
5
335 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…

821 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