SQL REPLACE VARIABL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RAW

    #1

    SQL REPLACE VARIABL

    Hi I have a little problem here with my code Iam asp user and Im trying
    to[color=blue]
    > 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=Micro soft.Jet.OLEDB. 4.0; Data
    > Source="& _
    > 'Server.MapPath ("../NEWMGS/dbcontainer/content.mdb")
    >
    > 'Absolute connection
    > Dim strConnection as String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
    > Source=D:\works \WEBS\NEWMGS\db container\conte nt.mdb"
    > DIM setNiveles AS INTEGER
    > DIM setContenido AS STRING
    > DIM setPagina AS STRING
    >
    > 'requesting my variable forma a querystring
    >
    > setPagina = Request.QuerySt ring("PAGINA")
    > setNiveles = Request.QuerySt ring("NIVELES")
    > setContenido = Request.QuerySt ring("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[/color]
    FROM[color=blue]
    > content WHERE PAGINA = " + Replace(setPagi na, "'", "''") + ""
    > *************** *****
    >
    > DIM objConnection AS NEW OledbConnection (strConnection)
    > DIM objCommand as NEW oledbCommand(my SqlStatment, objConnection)
    > DIM objDataReader as oledbDataReader
    >
    > try
    > objConnection.o pen()
    > objDataReader = objCommand.Exec uteReader()
    >
    > DO WHILE objDataReader.R ead()= true
    >
    > Response.write( objDataReader(s etPagina))
    > Response.write( "=")
    > Response.write( objDataReader(" NIVELES"))
    > 'Response.write (setNiveles)
    > 'Response.write ("&")
    > 'Response.write ("Contenido" )
    > 'Response.write ("=")
    > 'Response.write (setContenido)
    > 'Response.write ("&")
    >
    > loop
    > objDataReader.c lose()
    > objConnection.c lose()
    >
    > Catch e as EXCEPTION
    > end try
    > end Sub
    >
    > </Script>[/color]



  • Rajesh Patel

    #2
    Re: SQL REPLACE VARIABL

    try

    WHERE PAGINA = '" + Replace(setPagi na, "'", "''") + "'"

    you need to put single quotes after equal sign and between last 2 double
    quotes.

    Regards,

    Rajesh Patel

    "RAW" <de3a10@terra.c om> wrote in message
    news:efFK3QIrDH A.2528@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi I have a little problem here with my code Iam asp user and Im trying
    > to[color=green]
    > > 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=Micro soft.Jet.OLEDB. 4.0; Data
    > > Source="& _
    > > 'Server.MapPath ("../NEWMGS/dbcontainer/content.mdb")
    > >
    > > 'Absolute connection
    > > Dim strConnection as String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
    > > Source=D:\works \WEBS\NEWMGS\db container\conte nt.mdb"
    > > DIM setNiveles AS INTEGER
    > > DIM setContenido AS STRING
    > > DIM setPagina AS STRING
    > >
    > > 'requesting my variable forma a querystring
    > >
    > > setPagina = Request.QuerySt ring("PAGINA")
    > > setNiveles = Request.QuerySt ring("NIVELES")
    > > setContenido = Request.QuerySt ring("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[/color]
    > FROM[color=green]
    > > content WHERE PAGINA = " + Replace(setPagi na, "'", "''") + ""
    > > *************** *****
    > >
    > > DIM objConnection AS NEW OledbConnection (strConnection)
    > > DIM objCommand as NEW oledbCommand(my SqlStatment, objConnection)
    > > DIM objDataReader as oledbDataReader
    > >
    > > try
    > > objConnection.o pen()
    > > objDataReader = objCommand.Exec uteReader()
    > >
    > > DO WHILE objDataReader.R ead()= true
    > >
    > > Response.write( objDataReader(s etPagina))
    > > Response.write( "=")
    > > Response.write( objDataReader(" NIVELES"))
    > > 'Response.write (setNiveles)
    > > 'Response.write ("&")
    > > 'Response.write ("Contenido" )
    > > 'Response.write ("=")
    > > 'Response.write (setContenido)
    > > 'Response.write ("&")
    > >
    > > loop
    > > objDataReader.c lose()
    > > objConnection.c lose()
    > >
    > > Catch e as EXCEPTION
    > > end try
    > > end Sub
    > >
    > > </Script>[/color]
    >
    >
    >[/color]


    Comment

    Working...