Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I keep receiving an error on my asp.net application which says:

 

Server Error in '/' Application.

--------------------------------------------------------------------------------

 

Line 1: Incorrect syntax near ')'.

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: Line 1: Incorrect syntax near ')'.

 

I believe this may be because I am passing a session variable into my SQL statement to search records. Because the user has kept the browser open and inactive for longer than 20 mins (my session timeout) this resets the session variable and cause the application to crash because it has no variable to search for.

 

SqlSelectCommand3.CommandText = _

"SELECT [Pri Key], ProNu, Supplier, ConfirmedDate, Confirmed " & _

"FROM POP_Parts " & _

"WHERE ProNu = '" & ProjectNo & "' AND Supplier = '" & Session("SupplierID") & "'"

 

 

Any ideas on a solution would be appreciated.

 

Thanks

  • Administrators
Posted (edited)

You should check if the item in the session is nothing before attempting to use it in a query.

 

If Not Session("SupplierID") Is Nothing Then
   SqlSelectCommand3.CommandText = _
   "SELECT [Pri Key], ProNu, Supplier, ConfirmedDate, Confirmed " & _
   "FROM POP_Parts " & _
   "WHERE ProNu = '" & ProjectNo & "' AND Supplier = '" & Session("SupplierID") & "'"
End If

Also you are probably better off using either a stored procedure or a parameterised query rather than concatenating strings together (search these forums and you will find several threads on the hows and whys).

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...