Reputation: 25
SqlCommand cmd = new SqlCommand("Insert into [f_present] Values (@faculty_id, @name, @designation, @gender, @date, @status, @remarks)", con.active());
cmd.Parameters.AddWithValue("@faculty_id", fIdtxt.Text);
cmd.Parameters.AddWithValue("@name", fNametxt.Text);
cmd.Parameters.AddWithValue("@designation", fDestxt.Text);
cmd.Parameters.AddWithValue("@gender", fGendertxt.Text);
cmd.Parameters.AddWithValue("@date",dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@status", comboBox1.Text);
cmd.Parameters.AddWithValue("@remarks", remarksTxt.Text);
cmd.ExecuteNonQuery();
I get this error:
Conversion failed when converting date and/or time from character string
Upvotes: 1
Views: 1008
Reputation: 1073
You can change the date parameter with DateTimePicker
value like this
cmd.Parameters.AddWithValue("@date",dateTimePicker1.Value.ToString("yyyy-MM-dd"));
Upvotes: -2
Reputation: 28499
Don't use the text representation but the value.
cmd.Parameters.AddWithValue("@date", dateTimePicker1.Value);
Upvotes: 2