Erro Syntax Sql Join in c# with sql server

-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)";
c#
sql-server
visual-studio
asked on Stack Overflow Jun 4, 2018 by Pc Zuhdan • edited Jun 4, 2018 by Pc Zuhdan

1 Answer

-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)";
answered on Stack Overflow Jun 4, 2018 by Nick.McDermaid

User contributions licensed under CC BY-SA 3.0