我正在使用C#和Asp.Net。我有以下數據適配器和數據集:用數據適配器填充數據集查詢結果C#Asp.Net
SqlDataAdapter da_Select_Matching_Records;
DataSet ds_for_showing_X_Rows_Cols = new DataSet();
我要填寫數據集ds_for_showing_X_Rows_Cols
與查詢結果。這裏是我的代碼:
con = new SqlConnection("Data Source=local;Initial Catalog=Test;Integrated Security=True");
da_Select_Matching_Records = new SqlDataAdapter("Select BusinessSector5.Description_DE, SubCategory.Kategorie "+
"FROM Match_Subcategory_BusinessSector5 INNER JOIN "+
" SubCategory ON Match_Subcategory_BusinessSector5.SubCategoryID = SubCategory.ID INNER JOIN "+
" BusinessSector5 ON Match_Subcategory_BusinessSector5.BusinessSector5ID = BusinessSector5.ID", con);
//Filling of Data Set
da_Select_Matching_Records.Fill(ds_for_showing_X_Rows_Cols, "Description_DE, Kategorie");
我得到這個錯誤,在我填寫數據集的行上。我在Sql Server管理工作室中使用了查詢並運行了OK。
Incorrect syntax near the keyword INNER.
你應該paramaterize你的查詢也避免SQL注入:http://msdn.microsoft.com/en-us/ library/bbw6zyha(v = vs.110).aspx – hutchonoid
在每行添加一個空格 –