SQL VARIABLE

  • Thread starter Thread starter Darrin J Olson
  • Start date Start date
D

Darrin J Olson

Is it because you are using the '+' sign for concatenating your string in
VB? Should you be using '&'?

-Darrin
 
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>
 
It may help us to know what datatype the PAGINA column is.

It would also help if we knew what error you are getting.

If pagina is meant to be one to the string datatypes

Try this
DIM mySqlStatment as string = String.Format("Select PAGINA, NIVELES,
CONTENIDO, LINKS FROM content WHERE PAGINA = ""{0}""", Replace(setPagina,
"'", "''"))

HTH
Brian W
 
Hi I try your suggestion to change the + by the & where I concatanate

but I still have the same problem
let me explain when I pass my string with my variable example
whatever.aspx?Pagina=back_0

my page suposed to bring me the data from this record
and my code suppose to replace sql statement with my variable
and I dont know what Iam doing wrong this is not working
 
Back
Top