[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Date format SQL

Posted on 2012-03-22
2
Medium Priority
?
296 Views
Last Modified: 2012-03-22
Hi,

I am trying to insert a date from a textbox that I have brought in from SQL back into SQL and I keep getting the error:

Conversion failed when converting date and/or time from character string.

--------------------------------------------------------------------------------------------------------------------------------

This is the code im using to pull the date from SQL to my ASP.NET page

txtDate.Text = DateTime.Parse(newsContent.Rows[0]["date"].ToString()).ToShortDateString();

--------------------------------------------------------------------------------------------------------------------------------
Then I'm using the code belwo to update the date in SQL

DateTime dateNew;
dateNew = DateTime.Parse(txtDate.Text);

string query1 = "UPDATE smartChimps_news SET date='" + dateNew + "' WHERE newsid='" + newsid + "'";
0
Comment
Question by:hayward03
2 Comments
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 2000 total points
ID: 37753048
Use this

 "UPDATE smartChimps_news SET date=convert(datetime,'" + dateNew + "',103) WHERE newsid='" + newsid + "'";
0
 

Author Closing Comment

by:hayward03
ID: 37753237
Wordked perfectly first time round.

Thanks
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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 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