Link to home
Start Free TrialLog in
Avatar of hayward03
hayward03

asked on

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 + "'";
ASKER CERTIFIED SOLUTION
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hayward03
hayward03

ASKER

Wordked perfectly first time round.

Thanks