Solved

Parameter issue with DateTime

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Suggested Courses

738 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