2013-11-22 52 views
1

我正在使用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. 
+2

你應該paramaterize你的查詢也避免SQL注入:http://msdn.microsoft.com/en-us/ library/bbw6zyha(v = vs.110).aspx – hutchonoid

+0

在每行添加一個空格 –

回答

3

您需要在該行的末尾添加一個空格:

"FROM Match_Subcategory_BusinessSector5 INNER JOIN"+ 

"FROM Match_Subcategory_BusinessSector5 INNER JOIN "+ 

這一行也一樣:

"SubCategory ON Match_Subcategory_BusinessSector5.SubCategoryID = SubCategory.ID INNERJOIN"+ 

你之間也沒有空格和JOIN

所以確認,添加尾部空間,所有的線條和內部之間的空間,並加入

+0

是的,我添加了空間,但仍然收到相同的錯誤。然後,我還在其他行添加了空間,但仍然收到相同的錯誤。 – Kamran

+0

該行最後的空格:Select BusinessSector5.Description_DE,SubCategory.Kategorie「+ – hutchonoid

+0

INNERJOIN即INNER JOIN之間的空格 – hutchonoid

相關問題