Kirix Support Forums

Get Record count

Please post any help questions, requests or other feedback here.

Get Record count

Postby abenitez77 on Thu Feb 24, 2011 11:44 am

I am trying to get the record count to use for my progress bar. I am using the code below to optain the record count on a SQL Server table. Is this correct? on the alert below...it returns a "undefined" msg.

var RowCount
var db3
// Create our connection to SQL server.
db3 = new DbConnection("mssql://" + textbox.getText() + ":1434/" + selected_items2[i]);

// Get the Row count for our table to use in the Progressbar
RowCount = db3.execute("Select Count(*) As Cnt From [" + selected_items[x] + "]");
alert(RowCount.Cnt);
abenitez77
Registered User
 
Posts: 143
Joined: Fri Jan 21, 2011 12:42 pm

Re: Get Record count

Postby Aaron on Thu Feb 24, 2011 12:35 pm

The execute() function returns a result set. Before accessing a field in the result set, you have to get the first row:

Code: Select all
// select the rows and display the values
var result = db.execute("SELECT * FROM mytable");

// get the first row
result.next();

// get the field
var rowcount = result.rowcount;
Aaron Williams
Kirix Support Team
User avatar
Aaron
Kirix Support Team
 
Posts: 120
Joined: Fri Dec 16, 2005 3:01 pm

Re: Get Record count

Postby abenitez77 on Thu Feb 24, 2011 2:34 pm

Still the same error. This is what i changed it to. I added another alert to see if my table name was coming up right in my variable and it is.

// Create our connection to SQL server.
db3 = new DbConnection("mssql://" + textbox.getText() + ":1434/" + selected_items2[i]);

// Get the Row count for our table to use in the Progressbar
RecCount = db3.execute("Select * From [" + selected_items[x] + "]");
RecCount.next();
var rows = RecCount.rowcount;
alert(selected_items[x]);
alert(rows);
abenitez77
Registered User
 
Posts: 143
Joined: Fri Jan 21, 2011 12:42 pm

Re: Get Record count

Postby abenitez77 on Thu Feb 24, 2011 2:42 pm

My bad... I fixed it...here is what it should have been:

// Get the Row count for our table to use in the Progressbar
RecCount = db3.execute("Select Count(*) as Cnt From [" + selected_items[x] + "]");
RecCount.next();
var rows = RecCount.Cnt;
alert(selected_items[x]);
alert(rows);
abenitez77
Registered User
 
Posts: 143
Joined: Fri Jan 21, 2011 12:42 pm

Return to Strata Help & Feedback