-3

I Have some error when i add sql inner join Here's error

Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'SellingDetail'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolea'Lks_itSoftware.vshost.exe' (CLR v4.0.30319: Lks_itSoftware.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'Lks_itSoftware.vshost.exe' (CLR v4.0.30319: Lks_itSoftware.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. n asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Lks_itSoftware.InputSellingForm.showData() in E:\Zuhdan\Sekolah\LKS\Lks_itSoftware\Lks_itSoftware\InputSellingForm.cs:line 44 ClientConnectionId:ddcfb16a-208c-40c0-be48-b3a296ef673c Error Number:102,State:1,Class:15

and Here's my code

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)";
Pc Zuhdan
  • 1
  • 1

1 Answers1

-2

If you did some basic troubleshooting - printing the string - you'd see that you need to put a space before each closing quote. i.e.

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)";
Nick.Mc
  • 18,304
  • 6
  • 61
  • 91
  • With almost 11k, you should know already that typo questions should be closed instead of answered. Also, there is absolutely no point in all those concatenations when you could have just made it a constant string literal – Camilo Terevinto Jun 04 '18 at 22:58
  • it seems more like a typo to me. It seems like the poster doesn't actually know that you need to do this. Regardless, I'm sure the OP has already abandoned the question. – Nick.Mc Jun 04 '18 at 23:04
  • @Camilo About the constant; you are right that it should be one, but adding the `const` keyword would suffice, the concatenations can stay as-is as the compiler takes care of them. – pfx Jun 04 '18 at 23:15
  • Funny thing is, for once I decided I would answer instead of comment (I almost always comment) and you guys are _ruthless_ haha – Nick.Mc Jun 04 '18 at 23:17
  • @pfx I am very aware of that, but it is much cleaner (at least to me) to have a literal than concatenations. I wasn't referring to adding `const` though – Camilo Terevinto Jun 04 '18 at 23:17
  • @Nick.McDermaid I think you meant Entity Framework? Haha, yeah, that's most likely the case here. – Camilo Terevinto Jun 04 '18 at 23:23
  • We are quibbling over how the query should be written here and my understanding is that if you were using EF you would write the query in LINQ – Nick.Mc Jun 04 '18 at 23:52