View Full Version : Recordset basics
gorilla1
03-02-2003, 05:20 AM
if I have defined a recordset as below, Response.Write objRS(0) will print the name and place for the first instance, xxx and abc.
What is the syntax to print out just the name field for that first instance (xxx)?
Set objRS = Server.CreateObject("ADODB.Recordset" )
objRS.CursorLocation = 3 ' adUseClient
objRS.Fields.Append "Name", 200, 100
objRS.Fields.Append "Place", 200, 50
objRS.Open
objRS.AddNew
objRS("Name" ) = "xxx"
objRS("Place" ) = "abc"
objRS.AddNew
objRS("Name" ) = "yyy"
objRS("Place" ) = "def"
Mhtml
03-02-2003, 06:06 AM
You mean to query it do you not?
gorilla1
03-02-2003, 06:13 AM
Mhtml,
I'm sorry, I am a beginner with this. I know that if I issue the
Response.Write objRS(0) , the Name and Place for the first recordset objRS(0) will display ("xxx" and "abc"). I would like to get at the Name and Place individually within that recordset as I want to set other variables equal to them.
G
oracleguy
03-02-2003, 06:41 AM
objRS.Fields(0) will return just the name
objRS.Fields(1) will return just the place
You also can use the .Fields syntax as follows: objRS.Fields("FieldName")
Mhtml
03-02-2003, 06:48 AM
ahhh.. right. I see what ya mean now.
I've been learning python for the last month or so without thinking of vb so I've got to get my memory going again.
gorilla1
03-02-2003, 02:28 PM
Thanks, that helps. Another question, though. What is the syntax for defining a decimal field and specifying the number of decimal places. This will define an adDecimal field:
objRS.Fields.Append "Name2", 14
But how to define two digits? It would seem this might work?
objRS.Fields.Append "Name2", 14 2
But I can't find it documented how to do this.
G
oracleguy
03-03-2003, 11:17 PM
I'm not getting what your saying exactly.
You want to add a decimal number onto the end of one of the fields? Is that it?
gorilla1
03-07-2003, 04:04 PM
I wanted to be able to acccess the decimal portion of a field. This worked:
objRS.Fields.Append "Rank", 14 ' adDecimal
objRS.Fields("Rank" ).NumericScale = 2
whammy
03-08-2003, 03:13 AM
Hmm, interesting, I've never had to do anything like that, I usually use float datatype in SQL Server and calculate stuff very simply like that.
That's interesting, though.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.