Date format SQL

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 + "'";
hayward03Asked:
Who is Participating?
 
Lalit ChandraConnect With a Mentor Commented:
Use this

 "UPDATE smartChimps_news SET date=convert(datetime,'" + dateNew + "',103) WHERE newsid='" + newsid + "'";
0
 
hayward03Author Commented:
Wordked perfectly first time round.

Thanks
0
All Courses

From novice to tech pro — start learning today.