Sunday 22 September 2013

How to get list of field names of a table using activex dataobject in VB6

Database used : Oracle 11g
Client used : Oracle Net8 client
Application developed in Visual Basic 6.0

We are going to print the output in a multiline textbox
'---------------------------------------------------------------------------------------------------------------------
' Declaration
option explicit
private con as ADODB.Connection
private rs as ADODB.Recordset

private sub Form_Load()
  set con = new ADODB.Connection
  if not con is nothing then exit sub

  con.ConnectionString="Provided=MSDAORA.1;user id=hr_db;password=hr_db;Datasource=ORA"  ' Datasource is the service name configure in TNSNAMES.ora file.

 con.Open

 rs.Open "select * from employee_master",con,adOpenDynamic
dim fld

text1.Text="List of field names in the table employee_master : "
if not rs.EOF
   for each fld in rs.Fields
     text1.text = text1.text & fld.Name & "," & vbcrlf
   next fld
end if
rs.close
con.close
set rs=nothing
set con=nothing
end sub

No comments: