Solved

Date format SQL

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

22 Experts available now in Live!

Get 1:1 Help Now