Problem with SQL and Session Variable

Results 1 to 2 of 2

Thread: Problem with SQL and Session Variable

  1. #1
    Join Date
    Dec 1969

    Default Problem with SQL and Session Variable

    I&#039;m getting the following error:<BR><BR>Compiler Error Message: BC30059: Constant expression is required.<BR><BR>Source Error: <BR><BR>Line 39: "ON Proposal_ID.PROPOSAL_ID = Proposal_ID_PID_Year.PROPOSAL_ID " & _<BR>Line 40: "WHERE (((Proposal_ID_PID_Year.PROPOSAL_ID)=[Proposal_ID].[PROPOSAL_ID]) " & _<BR>Line 41: "AND ([Data].[PID]=" & cstr(Session("TempPID")) & "))"<BR>Line 42: <BR>Line 43: Dim da as OleDbCommand = new OleDBCommand(SQL, con)<BR> <BR><BR>Source File: c:inetpubwwwroot
    evisions.aspx Line: 41 <BR><BR>With the following statement:<BR><BR>const SQL As String = "SELECT Proposal_ID.PROPOSAL_ID " & _<BR> "FROM Proposal_ID " & _ <BR> "INNER JOIN (Data INNER JOIN Proposal_ID_PID_Year " & _<BR> "ON Data.PID = Proposal_ID_PID_Year.PID) " & _<BR> "ON Proposal_ID.PROPOSAL_ID = Proposal_ID_PID_Year.PROPOSAL_ID " & _<BR> "WHERE (((Proposal_ID_PID_Year.PROPOSAL_ID)=[Proposal_ID].[PROPOSAL_ID]) " & _<BR> "AND ([Data].[PID]=" & cstr(Session("TempPID")) & "))"<BR><BR>Please help! Thanks.<BR>

  2. #2
    Join Date
    Dec 1969

    Default Nope, not at all...

    Has nothing to do with SQL. Has nothing to do with Session variable.<BR><BR>You used the keyword CONST and that means that, by definition, you can&#039;t invoke any functions in the value being assigned to the variable. Period.<BR><BR>CONST variable values *MUST* be able to be evaluated AT COMPILE TIME.<BR><BR>Clearly, since this string depends upon a session variables value that CAN NOT BE KNOWN until run-time, you are violating the rules of CONST.<BR><BR>Change CONST to DIM.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts