SQL VARIABLE

Discussion in 'ASP .Net Web Services' started by RAW, Nov 17, 2003.

  1. RAW

    RAW Guest

    Hi I have a little problem here with my code Iam asp user and Im trying
    to
    > use vb.net on this proyect
    >
    > Im trying to pass varible to the sql string this is my code
    >
    > <Script language="vb" runat="server">
    > Sub Page_Load()
    > 'relative connection
    > 'Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
    > Source="& _
    > 'Server.MapPath("../NEWMGS/dbcontainer/content.mdb")
    >
    > 'Absolute connection
    > Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
    > Source=D:\works\WEBS\NEWMGS\dbcontainer\content.mdb"
    > DIM setNiveles AS INTEGER
    > DIM setContenido AS STRING
    > DIM setPagina AS STRING
    >
    > 'requesting my variable forma a querystring
    >
    > setPagina = Request.QueryString("PAGINA")
    > setNiveles = Request.QueryString("NIVELES")
    > setContenido = Request.QueryString("CONTENIDO")
    > Response.write(setPagina)
    >
    > ********************
    > HERE RIGHT HERE ITS WHERE I'AM TRYING TO REPLACE THE VARIABLE
    > setPagina ---------------------------------------------~v
    > DIM mySqlStatment as string = "Select PAGINA, NIVELES, CONTENIDO, LINKS

    FROM
    > content WHERE PAGINA = " + Replace(setPagina, "'", "''") + ""
    > ********************
    >
    > DIM objConnection AS NEW OledbConnection(strConnection)
    > DIM objCommand as NEW oledbCommand(mySqlStatment, objConnection)
    > DIM objDataReader as oledbDataReader
    >
    > try
    > objConnection.open()
    > objDataReader = objCommand.ExecuteReader()
    >
    > DO WHILE objDataReader.Read()= true
    >
    > Response.write(objDataReader(setPagina))
    > Response.write("=")
    > Response.write(objDataReader("NIVELES"))
    > 'Response.write(setNiveles)
    > 'Response.write("&")
    > 'Response.write("Contenido")
    > 'Response.write("=")
    > 'Response.write(setContenido)
    > 'Response.write("&")
    >
    > loop
    > objDataReader.close()
    > objConnection.close()
    >
    > Catch e as EXCEPTION
    > end try
    > end Sub
    >
    > </Script>
    RAW, Nov 17, 2003
    #1
    1. Advertising

  2. RAW

    Manny Guest

    Do you need single quotes around the variable

    Change from
    WHERE PAGINA = " + Replace(setPagina, "'", "''") + "

    to
    WHERE PAGINA = '" + Replace(setPagina, "'", "''") + "'
    Manny, Nov 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dna
    Replies:
    1
    Views:
    1,273
  2. Froefel
    Replies:
    1
    Views:
    789
    Mark Rae [MVP]
    Jul 4, 2007
  3. mfglinux
    Replies:
    11
    Views:
    700
    Roberto Bonvallet
    Sep 12, 2007
  4. ecoolone
    Replies:
    0
    Views:
    756
    ecoolone
    Jan 3, 2008
  5. David Filmer
    Replies:
    19
    Views:
    240
    Kevin Collins
    May 21, 2004
Loading...

Share This Page