When I try to display database values in a gridview I get an error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'and'.
And code is
private void button1_Click(object sender, EventArgs e)
{
SqlDataAdapter adap;
DataSet ds;
SqlConnection cn = new SqlConnection(
@"Data Source=DILIPWIN\SQLEXPRESS;Initial Catalog=radb;Integrated Security=True");
cn.Open();
var home = new Home();
adap = new SqlDataAdapter(
"select roll_num, mark from marks where mark < 50 and dept_id=" +
home.cboxDept.SelectedValue + " and sem_id=" + home.cboxSem.SelectedValue +
" and subject_id=" + home.cboxSubject.SelectedValue + " and batch_id= " +
home.cboxBatch.SelectedValue + " and cls_id=" + home.cboxClass.SelectedValue, cn);
ds = new System.Data.DataSet();
adap.Fill(ds, "dataGridView1");
dataGridView1.DataSource = ds.Tables[0];
}