I have a DateTimePicker(dtp) and an Add Button.
I saved 'birthday' as 'date' in my database.
Now I dont know how to save the data from dtp into database after click Add button.
Please help. Thank you. Here is my wrong code with error:
conversion failed when converting date and/or time from character string
private void btnAdd_Click(object sender, EventArgs e)
{
cnn.Open();
DateTime dtp_text = Convert.ToDateTime(dtp.Text);
int gt = 0;
if (rdoMale.Checked == true)
gt = 1;
else if (rdoFemale.Checked == true)
gt = 0;
string sql = "insert into NV values ('" + txtId.Text + "', N'" + txtName.Text + "',N'" + dtp_text + "')";
SqlCommand ins = new SqlCommand(sql, cnn);
ins.CommandType = CommandType.Text;
ins.ExecuteNonQuery();
Load();
cnn.Close();
}