I need to store the date fetch from the ASP.Net text box into a SQL Server 2008 date column.
I am getting the following exception message.
Conversion failed when converting date and/or time from character string.
My code is:
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
int n=4;
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection(<Connection String>);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string query = "insert into temp values('" + TextBox1.Text + "')";
cn.Open();
cmd = new SqlCommand(query, cn);
cmd.ExecuteNonQuery();
cn.Close();
Response.Write("Record inserted successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Please help ..
Thanks in advance
DateTimefield but your logic is passing it as a string.