Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 18th, 2006, 05:52 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default RecordCount & CursorLocation (SQL)

Hi,

I'm quite new to using SQL and I'm trying to get a query going from Javascript into a database (everything is being done client-side on one machine). The problem I'm having is that I can't get a count of the records in the database, I get a return of -1. Here is the code:

<script language = "javascript">

var cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Clevedon.mdb";
var adOpenForwardOnly = 0;
var adLockReadOnly = 1;
var adCmdText = 1;
var adUseClient = 1;
var tdStr = ""
var thStr = ""
        var cObj = new ActiveXObject("ADODB.Connection");
        var rSet = new ActiveXObject("ADODB.Recordset");
var qString="SELECT Categories.`Category Id`, Categories.`Category Name`, Categories.Deleted, Jobs.Priority, Jobs.`Logged at`, Jobs.`Next User Id`, Jobs.Notes, Categories.`Category Name`, Categories.`Category Id`, Categories.Deleted, Categories.`Category Name`, Categories.`Category Id`, Categories.`Category Name`, Categories.Deleted, Jobs.`Job Id`, Jobs.`Customer Id`, Jobs.`Category Id`, Jobs.Priority, Jobs.`Logged at`, Jobs.`To complete by`, Jobs.`Completed on`, Jobs.`Next User Id`, Jobs.Notes, Jobs.`Hours Spent`, Jobs.Problem, Jobs.Solution, Jobs.`To do`, Jobs.Cost, Jobs.`Completed on` FROM `C:\\CLEVEDON`.Categories Categories, `C:\\CLEVEDON`.Jobs Jobs WHERE Categories.`Category Id` = Jobs.`Category Id`"; //sql string to use (no probs with this so you can ignore

cObj.Open (cString); //open a connection
        rSet.CursorLocation = adUseClient //trying to set cursor location to be client

    rSet.Open(qString,cObj,adOpenForwardOnly,adLockRea dOnly,adCmdText);
        alert(rSet.CursorLocation)//this comes back as client
        alert(rSet.RecordCount)//comes back -1
            for (i = 1; i < rSet.Fields.Count; i++)
            {
            thStr+= " <td> " + rSet.Fields(i).Name + "</td>"
            }
            for (j = 1; j < rSet.Fields.Count; j++)
            {
            tdStr += "<td> " + rSet.Fields(j).Value + "</td>"
            }
        rSet.Close(); //close the recordset
cObj.Close(); //close the connection
        document.write ("<table><tr>" + thStr + "</tr><tr>" + tdStr + "</tr></table>")

</script>

When I googled the problem I'm having it returns results saying that I need the CursorLocation to be set to client, as "Dynamic Cursors" don't support RecordCount. I've tried to set the CursorLocation to be client, but I'm still getting the same result of -1?

Any help always much appreciated
Thanks
Joe

'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
__________________
\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
Reply With Quote
  #2 (permalink)  
Old December 18th, 2006, 08:35 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I sorted it!

Here is the finished code (the tabling code is a bit messy, but it will do till I find a neater solution):

<script language = "javascript">

var cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Clevedon.mdb";
var adOpenKeyset = 1;
var adLockOptimistic = 3;
var adCmdText = 1;
var adUseClient = 3;
var tdStr = ""
var thStr = ""
        var cObj = new ActiveXObject("ADODB.Connection");
        var rSet = new ActiveXObject("ADODB.Recordset");
        rSet.CursorLocation = adUseClient
        cObj.CursorLocation = adUseClient
var qString="SELECT Customers.`Customer Name`, Categories.`Category Name`, Jobs.Problem FROM `C:\\CLEVEDON`.Categories Categories, `C:\\CLEVEDON`.Customers Customers, `C:\\CLEVEDON`.Jobs Jobs WHERE Categories.`Category Id` = Jobs.`Category Id` AND Customers.`Customer Id` = Jobs.`Customer Id`";

cObj.Open (cString);


    rSet.Open(qString,cObj,adOpenKeyset,adLockOptimist ic,adCmdText);

            rSet.MoveFirst
            for (i =0; i < rSet.Fields.Count; i+=1)
                {
                thStr+= "<td class = tdClass>" + rSet.Fields(i).Name + "</td>"
                }
                    for (rCount = 0; rCount < rSet.RecordCount; rCount+=1)
                    {
                            for(counter = 0; counter <rSet.Fields.Count; counter+=1)
                            {
                                tdStr += "<td> " + rSet.Fields(counter).Value + "</td>"
                            }
                                if (counter =rSet.Fields.Count)
                                {
                                tdStr+="<tr>"
                                }
                        rSet.AbsolutePosition+=1
                    }

        rSet.Close();
cObj.Close();
        document.write ("<table><tr>" + thStr + "</tr><tr>" + tdStr + "</table>")

</script>

Cheers!

Joe

'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal Report & VB6 & SQL Server wlho VB How-To 2 June 5th, 2013 01:58 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
recordcount & absoluteposition cici Classic ASP Basics 2 May 14th, 2004 06:54 AM
sql & join tables & find a field in multiple table trangd Beginning PHP 2 January 29th, 2004 07:18 PM
recordcount & stored procedures eddiema Classic ASP Databases 2 October 9th, 2003 10:54 AM



All times are GMT -4. The time now is 04:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.