: : : : : : : : The code is:
: : : : : : : :
: : : : : : : : <%pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : : : : : : & "WHERE username=" & uname
: : : : : : : :
: : : : : : : : Set cnnPoints = Server.CreateObject("ADODB.Connection")
: : : : : : : : cnnPoints.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
: : : : : : : : & "DBQ=" & Server.MapPath("logindb.mdb"))
: : : : : : : :
: : : : : : : : Set rstPoints = cnnPoints.Execute(pointsSQL)
: : : : : : : : 'line 84 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: : : : : : : : %>
: : : : : : : :
: : : : : : : :
: : : : : : : : The Error is:
: : : : : : : : [quote]
: : : : : : : : Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
: : : : : : : :
: : : : : : : : [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
: : : : : : : :
: : : : : : : : /lego614/db/login_db.asp, line 84
: : : : : : : : [/quote]
: : : : : : : :
: : : : : : : : YES, I did dim the variables/give uname a correct value and YES the database/table exists.
: : : : : : : :
: : : : : : : : What is wrong with this code!
: : : : : : : :
: : : : : : :
: : : : : : : My guess is that your username field is a text/varchar field.You need single quotes around string values:
: : : : : : :
: : : : : : : <%pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : : : : : & "WHERE username='" & uname &"'"
: : : : : : :
: : : : : : : Set cnnPoints = Server.CreateObject("ADODB.Connection")
: : : : : : : cnnPoints.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
: : : : : : : & "DBQ=" & Server.MapPath("logindb.mdb"))
: : : : : : :
: : : : : : : Set rstPoints = cnnPoints.Execute(pointsSQL)
: : : : : : :
: : : : : : : %>
: : : : : : :
: : : : : : :
: : : : : :
: : : : : :
: : : : : : OK. The new error messsageis:
: : : : : : [quote]
: : : : : : Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
: : : : : :
: : : : : : [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''username='Lego614'.
: : : : : :
: : : : : : /lego614/db/login_db.asp, line 84
: : : : : : [/quote]
: : : : : :
: : : : : : The code is now:
: : : : : :
: : : : : : <%pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : : : : & "WHERE 'username='" & uname
: : : : : :
: : : : : : Set cnnPoints = Server.CreateObject("ADODB.Connection")
: : : : : : cnnPoints.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
: : : : : : & "DBQ=" & Server.MapPath("logindb.mdb"))
: : : : : :
: : : : : : Set rstPoints = cnnPoints.Execute(pointsSQL)
: : : : : : 'line 84 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: : : : : : %>
: : : : : :
: : : : : :
: : : : :
: : : : :
: : : : : You got me wrong there,I meant single quotes around the field *values*,
: : : : : not the field *names*
: : : : :
: : : : :
: : : : : pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : : : & "WHERE username='" & uname &"'"
: : : : :
: : : : :
: : : :
: : : :
: : : : That just causes the syntax error:
: : : : [quote]
: : : : Microsoft VBScript compilation error '800a03ea'
: : : : Microsoft VBScript compilation error '800a03ea'
: : : :
: : : : Syntax error
: : : :
: : : : /lego614/db/login_db.asp, line 78
: : : :
: : : : & "WHERE username='" & 'uname'
: : : : -----------------------^
: : : : [quote]
: : : :
: : : : Did I put the quote in the right area?
: : : :
: : : : PS.
: : : : In another working part of the script unmae is set as the username that successfully loged in and uname is a variable set at that point.
: : : : All the variables are Dim'ed before the HTML, and far above the script that has the error.
: : : :
: : : :
: : :
: : : You could have just copy pasted what I showed and it would have worked...
: : :
: : : Okay,
: : :
: : : What you want in the sql is this :
: : :
: : : SELECT points FROM tblLoginInfo WHERE username='somename'
: : :
: : :
: : : That somename is what you are passing from the asp page.So you add that value in the sql as:
: : :
: : : pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : & "WHERE username='" & somename&"'"
: : :
: : :
: : :
: : : In your case,the variable name is uname ,so you do:
: : :
: : : pointsSQL = "SELECT points FROM tblLoginInfo " _
: : : & "WHERE username='" & uname &"'"
: : :
: : :
: : : Just copy paste that line in red and see what happens.
: : :
: : :
: :
: :
: : Alright. That code wasbeing bad, so I found a new snippet.
: :
: : <%
: : ' Declare our variables... always good practice!
: : Dim cnnSimple ' ADO connection
: : Dim rstSimple ' ADO recordset
: : Dim strDBPath ' path to our Access database (*.mdb) file
: :
: :
: : ' MapPath of virtual database file path to a physical path.
: : ' If you want you could hard code a physical path here.
: : strDBPath = Server.MapPath("logindb.mdb")
: :
: :
: : ' Create an ADO Connection to connect to the scratch database.
: : ' We're using OLE DB but you could just as easily use ODBC or a DSN.
: : Set cnnSimple = Server.CreateObject("ADODB.Connection")
: :
: : ' This line is for the Access sample database:
: : 'cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
: :
: : ' We're actually using SQL Server so we use this line instead:
: : cnnSimple.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
: : & "Initial Catalog=samples;User Id=samples;Password=password;" _
: : & "Connect Timeout=15;Network Library=dbmssocn;"
: :
: :
: : ' Execute a query using the connection object. It automatically
: : ' creates and returns a recordset which we store in our variable.
: : Set rstSimple = cnnSimple.Execute("SELECT points FROM tblLoginInfo Where username=") & uname
: :
: : %>
: :
: :
: : However, true to form, it does not work.
: : The error is
: : [quote]
: : Microsoft OLE DB Provider for SQL Server error '80004005'
: :
: : [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
: :
: : /lego614/db/login_db.asp, line 110
: : [/quote]
: :
: : What's wrong with this new snippet?
: :
:
:
: Is 10.2.1.214 the IP of you machine?
:
No....