I get the following SqlException when i am trying to insert into db from C# window application.
Conversion failed when converting datetime from character string.
This is my SQL Query:
CREATE TABLE orderbooking
(
orderdate datetime ,
clientname varchar(40) ,
deliverylocation varchar(30) ,
deliverydate datetime
)
Sqlexception on
cmd.ExecuteNonQuery();
This is my Add button code:
{
SqlConnection cnn = new SqlConnection(@"Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True");
cnn.Open();
SqlParameter p1 = new SqlParameter("@orderdate", dateTimePicker1.Text);
SqlParameter p2 = new SqlParameter("@clientname", comboBox1.Text);
SqlParameter p3 = new SqlParameter("@Delivery Location", textBox2.Text);
SqlParameter p4 = new SqlParameter("@Delivery Date", dateTimePicker2.Text);
string query = "insert into orderbooking values('" + p1.Value + "','" + p2.Value + "','" + p3.Value + "','" + p4.Value + "')";
SqlCommand cmd = new SqlCommand(query, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
button2.Enabled = false;
}
I have added this code:
SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD]
but same error please help :(
Timing is not displaying in sql server database :(
Thanks in Advance :rose::rose: