當我試圖在GridView中顯示數據庫值我得到一個錯誤:在GridView的顯示SQL Server數據庫中值顯示錯誤
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'and'.
而且代碼
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];
}
你可以發佈後的所有連接查詢? – NMK 2014-10-08 14:43:09
我假設你正在使用__WinForms__,實際上是使用__DataGridView__?請__always標籤適當_否則你浪費__WPF__人們的時間! (反之亦然..) – TaW 2014-10-08 14:50:14