简体   繁体   中英

problem saving date to mysql from asp.net

I m trying to save the date to mysql from jquery *DatePicker* from C#

string datetime = txtDate.Text + " " + time;//05/11/2011 5:30 pm                    

string getSQL1 = 
   "INSERT into tblconcertdetail 
   (Address, City, Pincode, Country, Concert_Date) 
   VALUES ('" + addr + "','" + txtCCity.Text + "','" + txtCpincode.Text + "','" +
   ddlCCountry.SelectedItem.Text + "','" + Convert.DateTime(datetime) + "')";

Here getsql1 shows me the date field filled but in database it stores 0000-00-00 00:00 value. I m not getting why it is so.

I also try convert.ToString(datetime) to.

As mentioned in comments, you have to use parameters for 2 reasons:

  1. Prevent SQL Injections.
  2. Handle data type conversions. In your case, handling the .NET DateTime type to its equivalent value in database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM