Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parameter issue with DateTime

Posted on 2009-05-07
5
Medium Priority
?
338 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 2000 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

Independent Software Vendors: 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

715 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