添加sql内连接时出现错误 这是错误
抛出异常:' System.Data.SqlClient.SqlException'在System.Data.dll中 System.Data.SqlClient.SqlException(0x80131904):' SellingDetail'附近的语法不正确。 在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) 在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose) 在System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean& dataReady) 在System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,Boolean async,Int32 timeout,Boolean asyncWrite) 在System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1完成,String methodName,Boolean sendToPipe,Int32 timeout,Boolean& usedCache,Boolea' Lks_itSoftware.vshost.exe'(CLR v4.0.30319:Lks_itSoftware.vshost .exe):已加载' C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Runtime.Caching \ v4.0_4.0.0.0__b03f5f7f11d50a3a \ System.Runtime.Caching.dll'。跳过加载符号。模块已经过优化,启用了调试器选项“Just My Code”。 ' Lks_itSoftware.vshost.exe' (CLR v4.0.30319:Lks_itSoftware.vshost.exe):已加载' C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Numerics \ v4.0_4.0.0.0__b77a5c561934e089 \ System.Numerics.dll&#39 ;。跳过加载符号。模块已经过优化,调试器选项“Just My Code'已启用。 n asyncWrite,Boolean inRetry) 在System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在E:\ Zuhdan \ Sekolah \ LKS \ Lks_itSoftware \ Lks_itSoftware \ InputSellingForm.cs中的Lks_itSoftware.InputSellingForm.showData():第44行 ClientConnectionId:ddcfb16a-208C-40c0-be48-b3a296ef673c 错误号码:102,状态:1,等级:15
这是我的代码
tring query = "SELECT Food.FoodName, SellingDetail.Qty, Food.Price, SellingDetail.Price AS Expr1" +
"FROM ((SellingDetail INNER JOIN" +
"Food ON SellingDetail.FoodId = Food.Foodid)INNER JOIN" +
"SellingHeader ON SellingDetail.SellingId = SellingHeader.SellingId)INNER JOIN(" +
"Employee ON SellingHeader.EmployeeId = Employee.EmployeeId)";
答案 0 :(得分:-2)
如果你做了一些基本的故障排除 - 打印字符串 - 你会发现你需要在每个结束报价前加一个空格。即
string query = "SELECT Food.FoodName, SellingDetail.Qty, Food.Price,
SellingDetail.Price AS Expr1 " +
"FROM ((SellingDetail INNER JOIN " +
"Food ON SellingDetail.FoodId = Food.Foodid)INNER JOIN " +
"SellingHeader ON SellingDetail.SellingId =
SellingHeader.SellingId)INNER JOIN(" +
"Employee ON SellingHeader.EmployeeId = Employee.EmployeeId)";