con = new SqlConnection(cs);
con.Open();
DateTime current = DateTime.Now;
current = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"));
SqlCommand cmd = new SqlCommand(@"INSERT INTO CustomerDetails
(CustomerId, Date, Name, Gender, Address, Phone, Email, MobileNo,Notes)
VALUES ('" + txtCustomerID.Text + "','" + current + "','" +
txtCustomerName.Text + "','"+Gender+"','"+txtAddress.Text+"','" + txtPhone.Text
+ "','" + txtEmail.Text+"','" + txtMobileNo.Text + "','" +txtNotes.Text + "')",
con);
cmd.ExecuteNonQuery();
con.Close();
I am using this code in database my date has datetime datatype but when I am saving the data through form it is showing an error:
The conversion of a varchar datatype to a datetime data type resulted in an out-of-range value.
What is problem? Why is this error showing up?
Datefield if it really is aDate/Timedata type orvarcharas suggested by the error.