Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Updating a recordset - problem!

Posted on 2003-04-01
13
Medium Priority
?
203 Views
Last Modified: 2006-11-17
Hi all...

I am trying to update a record using SQL Server and getting the following error:

***********************************************************************************
Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'Hrs'.

/wfm/calctime.asp, line 69
***********************************************************************************

Here is my code:

<!-- #include virtual="/include/database_inc.asp" -->
<%

'connection function with this file
OpenSQL("calctime.asp")

     'declare recordset
     dim objUpd
     set objUpd = Server.CreateObject("ADODB.Recordset")
     
               'set lock and cursor types
               objUpd.locktype = adLockOptimistic
               objUpd.cursortype = adOpenKeyset
     
     'open the VacTable with the connection string from the OpenSQL()
     objUpd.Open "VacTable", connection

     'get unique user ID
     dim strEmpID
     strEmpID = request.cookies("CalcID")
     
     'calculation variables
     dim intCurrBal, intCurrTaken, intCurrDays, intTotal
     
     
     do while not (objUpd.EOF)
          'locate the user ID in the table
          if (strcomp (strEmpID, objUpd("EmplID"), vbtextcompare) = 0) then
         
               'declare variables
               intCurrBal = objUpd("Vac Hrs Bal YTD")
               intCurrTaken = objUpd("Vac Hrs Taken YTD")
               intCurrDays = request.cookies("DaysRequested")
               
               'get total hours used
               intTotal = (intCurrDays * 8)
               
               'update numbers
               intCurrBal = (intCurrBal - intTotal)
               intCurrTaken = (intCurrTaken + intTotal)
               
               'assign numbers back to the table
               objUpd("Vac Hrs Bal YTD") = intCurrBal
               objUpd("Vac Hrs Taken YTD") = intCurrTaken
               
               'update the record
               objUpd.update
               
               response.redirect("amenu.asp")
               
          else

               objUpd.MoveNext
               
          end if

     loop

               CloseSQL()
               
%>
               
And just to note, all the database field names are spelled correctly. Any help would be awesome.
0
Comment
Question by:cgamberg
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 9

Accepted Solution

by:
fz2hqs earned 150 total points
ID: 8246227
White space is never a good thing.

If you can, rename the columns replace the spaces with "_" will do.

You can try using square brackets i.e objUpd("[Vac Hrs Bal YTD]") however I am not certain that will do it
0
 

Author Comment

by:cgamberg
ID: 8246283
Thanks for your response. I tried your suggestions, unfortunately, both did not work.

I have been able to update many other recordsets, for example rs("Employee ID") no problem. For some reason, this is giving me a headache!
0
 
LVL 9

Expert Comment

by:fz2hqs
ID: 8246328
If you replaced the spaces with "_" you should have gotten a different message
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:arbert
ID: 8246508
What is the exact line above that generates the error?

Have you turned on ODBC tracing to see exactly what's being sent to the server?

Brett
0
 

Author Comment

by:cgamberg
ID: 8246588
The exact line that generates the error is

             objUpd.update

How do I turn on ODBC tracing? Sorry, not familiar with this....
0
 
LVL 34

Expert Comment

by:arbert
ID: 8246638
Go into your datasource administrator and there is a tracing tab.  Give it the trace file name and click on start tracing (you have to do this on the machine that's running your asp page).  DON'T FORGET TO TURN IT OFF WHEN YOU'RE DONE--it slows things down!

Brett
0
 

Expert Comment

by:bmilner
ID: 8246910
Just so that this is clear, you understand that fz2hqs is saying to rename the columns in your database, not the code of the page. Rename those using the "_" in place of spacing. This is a good convention to follow anyway.
0
 

Author Comment

by:cgamberg
ID: 8247076
bmilner, yep, I understand.

What I don't get is that in about 12 other ASP pages, I update and reference those two same fields without trouble.

I just can't seem to figure out why on this single page, it won't work.

Thanks, Chris
0
 

Expert Comment

by:bmilner
ID: 8247171
Yeah, I see why you wouldn't want to change it then. In my experience, that's exactly what tends to happen with names like that though; one place they work and another they don't.

All I can say is that the error is being thrown in the execution of the update meaning that some variable or name is not matching up correctly.

Sorry, I know this is not much help. All I can say is that if I were in your place, I would copy the table containing these values to another table, rename the column names, then change the code in your page to test and see if you get a different error. You could at least elimate that as a possibility then.

0
 
LVL 34

Expert Comment

by:arbert
ID: 8247224
Ya, sometimes ODBC errors aren't that specific--are you sure that the right datatypes are being passed in all cases?

That's why I recommended the ODBC logging--you can see the actual statement that is prepared....

Brett
0
 

Author Comment

by:cgamberg
ID: 8247751
I have figured it out.

When I changed the field names with "_" instead of spaces I received the following error:

***********************************************************************************
Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'Name'.

/wfm/calctime.asp, line 69
***********************************************************************************

"Name" is another field in this table, that's not being used in this routine. So instead of accessing the whole "VacTable" in this line of code:

    objUpd.Open "VacTable", connection

I added the following:

dim strSQL

strSQL = "SELECT [EmplID], [Vac_Hrs_Bal_YTD], [Vac_Hrs_Taken_YTD] FROM [VacTable];"

     objUpd.Open strSQL, connection

Now, it works wondefully.... GO FIGURE!

Thank you for all your suggestions! I'll give it to fz2hqs, who originally told me to change my naming conventions, and thus root out the problem.

Cheers,
Chris


0
 

Author Comment

by:cgamberg
ID: 8247770
Thanks fz2hqs....
0
 
LVL 34

Expert Comment

by:arbert
ID: 8247974
Name is a reserved word.....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question