Counter Problems!

Results 1 to 2 of 2

Thread: Counter Problems!

  1. #1
    Michael Deal Guest

    Default Counter Problems!

    I am tring to make a counter for my home page. This is the code that i have <BR>------begin code------------------------------------------------------------------------------------------------------------------------------------------------------- <BR>&#060;% <BR>Response.Buffer = True <BR>Response.Clear <BR><BR>Dim DBName, objConn, objRS, strSQL, TempVal <BR>DBName = server.mappath("counter.mdb") <BR><BR>Set objConn = Server.CreateObject("ADODB.Connection") <BR>objConn.ConnectionString = "DBQ=" & DBName & ";Driver={Microsoft Access Driver (*.mdb)};" <BR>objConn.Open <BR><BR>Set objRS = Server.CreateObject("ADODB.Recordset") <BR>strSQL = "SELECT * FROM count Where ID =1" <BR>Set objRS= objConn.execute(strSQL) <BR><BR>TempVal = objRS("Number") <BR>TempVal = TempVal + 1 <BR><BR>strSQL = "Update count Set Number = &#039;" & TempVal & "&#039; Where ID = &#039;1&#039;" <BR>Set objRS= objConn.execute(strSQL) <BR>Response.Redirect "welcome.htm" <BR>%&#062; <BR>-------------End code--------------------------------------------------------------------------------------------------------------------------------------------------- <BR>When i do this i get the error <BR>-----------------begin error-------------------------------------------------------------------------------------------------------------------------------------------- <BR>Microsoft OLE DB Provider for ODBC Drivers error &#039;80040e14&#039; <BR><BR>[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement. <BR><BR>/ChhsBeta/counter.asp, line 20 <BR>------------------End error---------------------------------------------------------------------------------------------------------------------------------------------

  2. #2
    Join Date
    Dec 1969

    Default RE: Counter Problems!

    What datatypes are the columns number and id defined as? If they are numeric there shall not be any single quotes surrounding the values. Also, count and number are not a good choice as identifiers as they are reserved words in most SQL dialects.<BR><BR>Furthermore, doing the select and adding one in your VB-script is quite unnecessary. You can do that calculation directly when you do the update.<BR><BR>&#060;% <BR>Response.Buffer = True <BR>Response.Clear <BR><BR>Dim DBName, objConn, strSQL<BR>DBName = server.mappath("counter.mdb") <BR><BR>Set objConn = Server.CreateObject("ADODB.Connection") <BR>objConn.ConnectionString = "DBQ=" & DBName & ";Driver={Microsoft Access Driver (*.mdb)};" <BR>objConn.Open <BR><BR>strSQL = "Update [count] Set [Number] = [Number] + 1 Where ID = 1" <BR>objConn.execute strSQL,,128 <BR>Response.Redirect "welcome.htm" <BR>%&#062; <BR><BR>The syntax [name] can be used when you have names that are reserved words in SQL. Preferrably I think that you should rename the table and the column. (The syntax with [] is not ANSI-standard but specific to Access and SQL server.)

Posting Permissions

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