How to get the column count and column name from resultset in database connction program?

Showing Answers 1 - 2 of 2 Answers

T.Gopi Chand

  • Jul 20th, 2006
 

i am giveing examples so that u can under sand easily.

1).example for recordcount

Set dbconn=createobject("adodb.connection")
dbconn.open "dsn=xxx"

Set objRecordset=createobject("ADODB.Recordset")
   objRecordset.open "select * from logintable",dbconn,1,3

   msgbox objRecordset.recordcount

2).for field names

For each x in objRecordset.fields
  msgbox (x.name)
Next

  Was this answer useful?  Yes

Uday Kumar. A

  • Sep 27th, 2006
 

Here is the solution to find the number of columns in record set and column headings:

conStr="driver=sql server;server=DT-CORP-ASTR-19;database=test;uid=sa;pwd=sa;"
qryStr="select * from empTable"
Set conObj=createobject("adodb.connection")
Set cmdObj=createobject("adodb.command")
Set recObj=createObject("adodb.recordset")
conObj.open conStr
set cmdObj.activeconnection=conObj
cmdObj.commandtext=qryStr
Set recObj=cmdObj.execute

colCount=recObj.fields.count  ' to retrieve the no. of columns in recordset
msgbox(colCount)
For i=0 to  colCount-1
 msgbox(recObj(i).name) 'to find the coumn names of recordset
Next

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions