Solved

Date format SQL

Posted on 2012-03-22
2
272 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 40
Response.Redirect Open new Form/tab/page? 5 30
Calling stored proc in EDMX 11 23
Turn on intranet settings 1 40
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now