|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP.Net/VB.Net - COUNTing records?
Afternoon all,
First time i've ever used a COUNT command as part of a select statement, and i have no idea how to use the information!!! I assumed (i feel a bit wrongly) that the resulting number would be stored in the variable as specified, e.g. Code:
ProductTotal = tobjConn.Execute("SELECT count(*) FROM Prices")
and then to call the variable was just a case of using this: Code:
<%= ProductTotal(0) %> I'm guessing this is entirely wrong from start to finish since i get this error: Quote:
I know it's really simple, but i've never used a COUNT before, so have no clue......... suggestions welcome and needed!!! Thanks! |
|
#2
|
||||
|
||||
|
that's not ASP.NET, it's VBScript.
learn about OleDbConnection, OleDbCommand and OleDbDataReader and I'm sure you'll be able to accomplish what you need easily. ![]() |
|
#3
|
|||
|
|||
|
Ah yes, posted in the wrong forum!! I'd be grateful if you could shift it to the classic ASP forum for me....
I'll have a read up on ole in the meantime... |
|
#4
|
||||
|
||||
|
Code:
Why <%= ProductTotal(0) %> vs. <%= ProductTotal %> ? Isn't ProductTotal just an integer?
__________________
Roger (.NET MCP) |
|
#5
|
||||
|
||||
|
Can't say I've ever executed a query like that.
My tried and tested method is something like:- Code:
strsql = "SELECT COUNT(*) As noRecords FROM Prices"
Set rs = Server.CreateObject("ADODB.RecordSet")
conn.open()
rs.open strsql,conn
ProductTotal = rs("noRecords")
rs.close
conn.close
set rs = nothing
set conn = nothing
Hope that helps
__________________
Policy Check I'd rather have a full bottle in front of me, than a full frontal lobotomy...
|
|
#6
|
||||
|
||||
|
--moved to the classic ASP forum
in theory, it's possible to read from recordset using the field index instead of the field name so can't see any obvious reason for the code to fail. try changing the code to: Code:
Dim ProductTotal, nRecordCount
Set ProductTotal = tobjConn.Execute("SELECT count(*) As MyCount FROM Prices")
nRecordCount = CLng(ProductTotal("MyCount"))
ProductTotal.Close
then use the variable nRecordCount in order to show/use the count. |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > ASP.Net/VB.Net - COUNTing records? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|