Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Using a variable to access a certain column in a database


Message #1 by steven_vints@y... on Mon, 26 Mar 2001 16:12:12
Hello,





I have the following problem:



Suppose the next code:



<%Dim columnspecification

  columnspecification = "name"



  Dim objRS

  Set objRS = Server.CreateObject("ADODB.RecordSet")



  objRS.Open "persons", .........



  Response.Write objRS(columnspecification) ??????

%>





How can I use the variable to access a certain column.  I always recieve 

the error: "Item cannot be found in the collection corresponding to the 

requested name or ordinal".

I am 100% sure that the columnname exists in the corresponding database.





Thanks for your help,



Steven
Message #2 by "Blake, Shane" <Shane.Blake@p...> on Mon, 26 Mar 2001 10:25:56 -0500
well... first make sure that you have data in your recordset...



if not objRS.EOF then

	response.write objRS(colunmspecificaiton)

end if



if a recordset is .bof and .eof then it's empty...



shane



-----Original Message-----

From: steven_vints@y... [mailto:steven_vints@y...]

Sent: Monday, March 26, 2001 10:25 PM

To: ASP Databases

Subject: [asp_databases] Using a variable to access a certain column in

a database





Hello,





I have the following problem:



Suppose the next code:



<%Dim columnspecification

  columnspecification = "name"



  Dim objRS

  Set objRS = Server.CreateObject("ADODB.RecordSet")



  objRS.Open "persons", .........



  Response.Write objRS(columnspecification) ??????

%>





How can I use the variable to access a certain column.  I always recieve 

the error: "Item cannot be found in the collection corresponding to the 

requested name or ordinal".

I am 100% sure that the columnname exists in the corresponding database.





Thanks for your help,



Steven

Message #3 by Steven Vints <steven_vints@y...> on Mon, 26 Mar 2001 08:55:49 -0800 (PST)
I am sure that there is data in the datastore ...



My specific question was the following:



Normally you receive the content of a database-cell by

using objRS("columnname")



How can I compose this statement when the columnname

is stored in a variable?



ex.: Dim name

     name = "person"



I tried already objRS(name) but it doesn't work ...



Thanks,



Steven

--- "Blake, Shane" <Shane.Blake@p...> wrote:

> well... first make sure that you have data in your

> recordset...

> 

> if not objRS.EOF then

> 	response.write objRS(colunmspecificaiton)

> end if

> 

> if a recordset is .bof and .eof then it's empty...

> 

> shane

> 

> -----Original Message-----

> From: steven_vints@y...

> [mailto:steven_vints@y...]

> Sent: Monday, March 26, 2001 10:25 PM

> To: ASP Databases

> Subject: [asp_databases] Using a variable to access

> a certain column in

> a database

> 

> 

> Hello,

> 

> 

> I have the following problem:

> 

> Suppose the next code:

> 

> <%Dim columnspecification

>   columnspecification = "name"

> 

>   Dim objRS

>   Set objRS = Server.CreateObject("ADODB.RecordSet")

> 

>   objRS.Open "persons", .........

> 

>   Response.Write objRS(columnspecification) ??????

> %>

> 

> 

> How can I use the variable to access a certain

> column.  I always recieve 

> the error: "Item cannot be found in the collection

> corresponding to the 

> requested name or ordinal".

> I am 100% sure that the columnname exists in the

> corresponding database.

> 

> 

> Thanks for your help,

> 

> Steven

> 
Message #4 by Imar Spaanjaars <Imar@S...> on Mon, 26 Mar 2001 22:42:59 +0200
The example you gave should word. Maybe name is a reserved keyword (at 

least it sounds like one)

Try this:



Dim sName

sName = "person"

objRS(sName)



HtH



Imar





At 08:55 AM 3/26/2001 -0800, you wrote:

>I am sure that there is data in the datastore ...

>

>My specific question was the following:

>

>Normally you receive the content of a database-cell by

>using objRS("columnname")

>

>How can I compose this statement when the columnname

>is stored in a variable?

>

>ex.: Dim name

>      name = "person"

>

>I tried already objRS(name) but it doesn't work ...

>

>Thanks,

>

>Steven



Message #5 by "Blake, Shane" <Shane.Blake@p...> on Mon, 26 Mar 2001 15:53:57 -0500
i understood your question.  my response is that there's another problem.



you're example _should_ work... 



shane



-----Original Message-----

From: Steven Vints [mailto:steven_vints@y...]

Sent: Monday, March 26, 2001 11:56 AM

To: ASP Databases

Subject: [asp_databases] RE: Using a variable to access a certain column

i n a database





I am sure that there is data in the datastore ...



My specific question was the following:



Normally you receive the content of a database-cell by

using objRS("columnname")



How can I compose this statement when the columnname

is stored in a variable?



ex.: Dim name

     name = "person"



I tried already objRS(name) but it doesn't work ...



Thanks,



Steven

--- "Blake, Shane" <Shane.Blake@p...> wrote:

> well... first make sure that you have data in your

> recordset...

> 

> if not objRS.EOF then

> 	response.write objRS(colunmspecificaiton)

> end if

> 

> if a recordset is .bof and .eof then it's empty...

> 

> shane

> 

> -----Original Message-----

> From: steven_vints@y...

> [mailto:steven_vints@y...]

> Sent: Monday, March 26, 2001 10:25 PM

> To: ASP Databases

> Subject: [asp_databases] Using a variable to access

> a certain column in

> a database

> 

> 

> Hello,

> 

> 

> I have the following problem:

> 

> Suppose the next code:

> 

> <%Dim columnspecification

>   columnspecification = "name"

> 

>   Dim objRS

>   Set objRS = Server.CreateObject("ADODB.RecordSet")

> 

>   objRS.Open "persons", .........

> 

>   Response.Write objRS(columnspecification) ??????

> %>

> 

> 

> How can I use the variable to access a certain

> column.  I always recieve 

> the error: "Item cannot be found in the collection

> corresponding to the 

> requested name or ordinal".

> I am 100% sure that the columnname exists in the

> corresponding database.

> 

> 

> Thanks for your help,

> 

> Steven

> 
Message #6 by "Dallas Martin" <dmartin@z...> on Mon, 26 Mar 2001 18:48:09 -0500
This code snippet worked!!!



<%

on error resume next



'*** Create and Open connection

set cnConn = Server.CreateObject("ADODB.Connection")

strConn = Application("strConn")

cnConn.Open(strConn)



set rs = cnConn.Execute("SELECT fname,lname FROM clients")



name="lname"



response.write("trying response.write(name)" & "<br>")

response.write(rs(name))



rs.close

set rs = nothing

cnConn.close

set cnConn = nothing

%>



Dallas







----- Original Message -----

From: "Steven Vints" <steven_vints@y...>

To: "ASP Databases" <asp_databases@p...>

Sent: Monday, March 26, 2001 11:55 AM

Subject: [asp_databases] RE: Using a variable to access a certain column i n

a database





> I am sure that there is data in the datastore ...

>

> My specific question was the following:

>

> Normally you receive the content of a database-cell by

> using objRS("columnname")

>

> How can I compose this statement when the columnname

> is stored in a variable?

>

> ex.: Dim name

>      name = "person"

>

> I tried already objRS(name) but it doesn't work ...

>

> Thanks,

>

> Steven

> --- "Blake, Shane" <Shane.Blake@p...> wrote:

> > well... first make sure that you have data in your

> > recordset...

> >

> > if not objRS.EOF then

> > response.write objRS(colunmspecificaiton)

> > end if

> >

> > if a recordset is .bof and .eof then it's empty...

> >

> > shane

> >

> > -----Original Message-----

> > From: steven_vints@y...

> > [mailto:steven_vints@y...]

> > Sent: Monday, March 26, 2001 10:25 PM

> > To: ASP Databases

> > Subject: [asp_databases] Using a variable to access

> > a certain column in

> > a database

> >

> >

> > Hello,

> >

> >

> > I have the following problem:

> >

> > Suppose the next code:

> >

> > <%Dim columnspecification

> >   columnspecification = "name"

> >

> >   Dim objRS

> >   Set objRS = Server.CreateObject("ADODB.RecordSet")

> >

> >   objRS.Open "persons", .........

> >

> >   Response.Write objRS(columnspecification) ??????

> > %>

> >

> >

> > How can I use the variable to access a certain

> > column.  I always recieve

> > the error: "Item cannot be found in the collection

> > corresponding to the

> > requested name or ordinal".

> > I am 100% sure that the columnname exists in the

> > corresponding database.

> >

> >

> > Thanks for your help,

> >

> > Steven




  Return to Index