Apr 24, 2018 12:28 PM|ODYSSEY-GB|LINK
I'm pretty new to asp.net, so I apologise if this is a basic question!
I'm getting an error when I call a function that's defined in a .vb file in my App_Code directory. The code of the function is:
Public Shared Function NextItemNumber(strItemTypeName As String) As Integer objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString) objConn.Open() Dim strSQLStatement = New String("If (SELECT MAX (Number) Number From Items.tbl" + strItemTypeName + ") IS NOT NULL" & vbCrLf & "SELECT Case MAX (Number) Number From Items.tbl" + strItemTypeName + "" & vbCrLf & "ELSE" & vbCrLf & "SELECT StartOffset from Items.tblItemTypes WHERE Name = '" + strItemTypeName + "'") objCmd = New SqlCommand(strSQLStatement, objConn) Dim intLastNumber = objCmd.ExecuteScalar() Dim intNextNumber = intLastNumber + 1 Return intNextNumber objConn.Close()End Function
When I load the page which calls this function, I get the error message:
Incorrect syntax near 'Number'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'Number'.
Can anyone suggest where to look for the fault? There are quite a few instances of 'Number' in the code, I'm not sure which one has the syntax error. I've tested the SQL Query in isolation using SQL Server Management studio, which is generating the results
I expect. I'm successfully calling other functions defined in the same .vb file as this one.