fetching data using 2 references in c# windows form

Viewed 17

can someone help me? I have a bulk data with several column where there is column name "NamaStasiun" (StationName) and "Tanggal" (Date). I want to fetch my data based on those 2 categories simultaneously where the stationname is in a combobox and date using 2 datetimepicker.

here is my code

private void DisplayDataGrid()

{

SqlCommand query2 = new SqlCommand("select NamaStasiun, Tanggal , Hour00, Hour01, etc, Hour23 from [TableName] where Namastasiun like '%" + comboBoxNamaStasiun.Text + "', Tanggal between '"+DatePickerAwal.Value.ToShortDateString()+"' and '"+DatePickerAkhir.Value.ToShortDateString()+"'", connection);

SqlDataAdapter dataadapter2 = new SqlDataAdapter();

DataTable datatable2 = new DataTable();

dataadapter2.SelectCommand = query2;

datatable2.Clear();

dataadapter2.Fill(datatable2);

datagridshowdataexport.DataSource = datatable2;

}

and it replied me with message "Incorrect syntax near ','."

But when I use only NamaStasiun as reference, it was work normally.

Thank you.

0 Answers
Related