I have a table called Tbl_Sud_Details
it has three columns:
Name is varchar(),
Course is varchar(),
DateofAdmission is Datetime(),
When I am inserting a date in the format dd/mm/yyyy
it gives the error:
Error:The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated
SqlCommand cmd = new SqlCommand("Insert into Tbl_Sud_Details(Name,Course,DateofAdmission)Values('" + ddlname.SelectedItem.Text + "','" + txtcourse.Text + "','" +Convert.ToDateTime(txtAdddate.Text).ToString("dd/MM/yyyy") + "')", con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "k1", "<script language=javascript> alert(\"data is save Successfully \"); </script>");
return;
}