我正在使用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管理工作室中使用了查询并且运行正常。
Incorrect syntax near the keyword INNER.
答案 0 :(得分:3)
您需要在此行的末尾添加空格:
"FROM Match_Subcategory_BusinessSector5 INNER JOIN"+
即
"FROM Match_Subcategory_BusinessSector5 INNER JOIN "+
这条线也一样:
"SubCategory ON Match_Subcategory_BusinessSector5.SubCategoryID = SubCategory.ID INNERJOIN"+
INNER
和JOIN
之间也没有空格。
因此,要确认,请为所有行添加尾随空格,并在内部和连接之间添加空格