At the moment of clicking the radiobutton "Current" I want the datagridview only to show me the most current data of the line that I select in the combobox. When I run the program it gives me the following error: Incorrect syntax near '11 -28-16 '. Initially I tried to take the datetimepicker date but it gave me the same error. How can I solve this?
Code:
private void btnFiltrar_Click(object sender, EventArgs e)
{
if (rbTodos.Checked) {
conexion.Open();
da = new SqlDataAdapter("select * from CWS where Family = '"+cbLine.Text+"' and Date between '" + dateTimePicker1.Value.ToString("MM/dd/yyyy") + "'and'" + dateTimePicker3.Value.ToString("MM/dd/yyyy") + "'", conexion);
DataSet DS = new DataSet();
da.Fill(DS, "CWS");
dataCWSreport.DataSource = DS.Tables["CWS"];
conexion.Close();
}
if (rbActual.Checked){
String fecha;
int fecha1 = lblShowDate.Text();
fecha = lblShowDate.ToString();
conexion.Open();
da = new SqlDataAdapter("select * from CWS where Family = '" + cbLine.Text + "' and Date '" + lblShowDate.Text + "'", conexion);
DataSet DS = new DataSet();
da.Fill(DS, "CWS");
dataCWSreport.DataSource = DS.Tables["CWS"];
conexion.Close();
}
}
PS: the data type of the Date column is 'date'.