When I execute the following query, I get the error message date is incompatible with int
:
textBox4.Text = dateTimePicker1.Value.ToShortDateString();
DataSet ds1 = new DataSet();
cmd.CommandText = "select ID_REPAS FROM CONSOMMER C , GROUPE G WHERE G.REF_GROUPE=C.REF_GROUPE AND C.dateEFF=G.dateEff and G.REF_GROUPE=" + textBox3.Text + "and C.dateEFF=" +dateTimePicker1.Value.ToShortDateString();
da2.Fill(ds1, "idrepas");
textBox2.Text = ds1.Tables["idrepas"].Rows[0][0].ToString();
Clearest and safest way is to use SQL parameters...
cmd.CommandText = "select ID_REPAS FROM CONSOMMER C , GROUPE G WHERE G.REF_GROUPE=C.REF_GROUPE AND C.dateEFF=G.dateEff and G.REF_GROUPE=@txtBox3Val and C.dateEFF=@shortDate";
command.Parameters.Add(new SqlParameter("txtBox3Val" , textBox3.Text));
command.Parameters.Add(new SqlParameter("shortDate", dateTimePicker1.Value.ToShortDateString());
Which helps to avoid hard to manage tack ('+') together code and prevents injections attacks.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments