Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
How do I assign what is returned from an SQL statement to a VB variable e.g:

select count (NGN_number) from NGN
where NGN_number = 'XXXXX'

how would I assign the count to a variable 'varCount' ?
 
you can create the variable in the SQL statement, along these lines

select count (NGN_number) as ngnCount from NGN
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
thinking about my reply that probably didn't give you the complete answer. I assume too much all the time
what you would need to do exactly is create a recordset object and do your SQL line the way I showed you above and then call the recordset after declaring your variable for the value.
so
select count (NGN_number) as NGNCount from NGN
where NGN_number = 'XXXXX'
NGN = RS("NGNCount")

is that along the lines of what you wanted A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
So if I do:

dim ngnCount

"SELECT count (NGN_number) as ngnCount from NGN where NGN_number = '0845641111'"

response.write(ngnCount)

I can access the variables contents?

As far as I can see SQL will put its count into its own ngnCount, but I can't seem to access it in the response.write.

I'd like to assign it to a vb variable and play with this from then on. How would I do this?
 
I'm using dreamweaver and here's the code below. How do I put in a recordset object and get the sql into the variable varCount?

dim varCount

set Check_NGN = Server.CreateObject("ADODB.Command")
Check_NGN.ActiveConnection = MM_UNCL_telecom_STRING
Check_NGN.CommandText = "SELECT count (NGN_number) as ngnCount from NGN where NGN_number = '08451112222'"
Check_NGN.CommandType = 1
Check_NGN.CommandTimeout = 0
Check_NGN.Prepared = true
Check_NGN.Execute()

???NGN = RS("NGNCount")???

response.write("Number of existing records = " & varCount)
 
try this

dim varCount
set RS = Server.CreateObject("ADODB.RecordSet")
set Check_NGN = Server.CreateObject("ADODB.Command")
Check_NGN.ActiveConnection = MM_UNCL_telecom_STRING
Check_NGN.CommandText = "SELECT count (NGN_number) as ngnCount from NGN where NGN_number = '08451112222'"
Check_NGN.CommandType = 1
Check_NGN.CommandTimeout = 0
Check_NGN.Prepared = true
Check_NGN.Execute()

varCount = RS("ngnCount")

response.write "Number of existing records = " & varCount
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Got the following message:

ADODB.Fields error '800a0cc1'

ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.

/telecom/add_NGN_1.asp, line 40

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top