Dim arrColumnNames()
Set con = CreateObject("Adodb.Connection")
Set rs = CreateObject("Adodb.RecordSet")
con.Open
"DSN=MappingTemplate_DSN;Server=SHALABHDIXIT-PC;DATABASE=EPM;UID=sa;Password=1234"
intTotalRecords = 0
int_rsIndex = 0
rs.Open "Select * from mapping_template",con
While rs.EOF <> True
ReDim Preserve arrColumnNames(intTotalRecords)
arrColumnNames(int_rsIndex ) = rs.Fields(int_rsIndex).Name
int_rsIndex = int_rsIndex + 1
intTotalRecords = intTotalRecords + 1
Wend
msgbox "Total Records = "+intTotalRecords
Regards
Shalabh Dixit
On Thu, Jul 21, 2011 at 9:08 PM, Kiran Ogeti <[email protected]> wrote:
> Thanks .. I am able to pull my recordset as well
>
> I using getstring for recordset.. but it return only the values but not
> column headers.. how to get column headers from DB
>
> Thanks again
>
> --- On *Thu, 7/21/11, Shalabh Dixit <[email protected]>* wrote:
>
>
> From: Shalabh Dixit <[email protected]>
> Subject: Re: connect to database
> To: [email protected]
> Date: Thursday, July 21, 2011, 10:26 AM
>
>
> You can use this function as well. This will return Array of values of
> connection state and connection properties which you can pass to other
> functions as well if required.
>
> conValues = ConnectDatabase("Mapping Template
> Connection","MappingTemplate_DSN","SHALABHDIXIT-PC","EPM","sa","12")
> conState = conValues(0)
> conProp = conValues(1)
>
>
> ''<Function>
> ''******************************Function
> Details***************************
> ''<Name>ConnectDatabase</Name>
> ''<Description>
> ''This function is used to connect to any database. Also it returns
> an Array of values containing Connection State and Connection properties.
> ''</Description>
> ''<Input Paramters>
> ''<Parameter Name="strConName" Type = "In">Contains Sample
> connection name</Parameter>
> ''<Parameter Name="strDSNName" Type = "In">Contains Name of Data
> source for a particular Database</Parameter>
> ''<Parameter Name="strServerName" Type = "In">Contains of Server
> name to connect with</Parameter>
> ''<Parameter Name="strDataBaseName" Type = "In">Contains name of
> database needs to be accessed</Parameter>
> ''<Parameter Name="strUserID" Type = "In">Contains userID of the
> database</Parameter>
> ''<Parameter Name="strPassword" Type = "In">Contains Password of
> the database</Parameter>
> ''</Input Paramters>
> ''<Output Paramters>
> ''<Parameter Name="conState" Type = "Out">Returns the connection
> state of database. Possible values for this parameter are :
> '' conState = 0 => Database Connection NOT Established
> Succefully
> '' conState = 1 => Database Connection Established Succefully
> ''</Parameter>
> ''<Parameter Name="conProp" Type = "Out">Returns the Database
> connection properties</Parameter>
> ''</Output Paramters>
> ''<Returns>
> '' Array containing Connection State and Connection properties
> ''</Returns>
> ''<Example>
> '' conValues = ConnectDatabase("Datamaker
> Connection","DataMaker_DSN","192.168.14.198","Datamaker","gtrep","gtrep")
> '' conState = conValues(0)
> '' conProp = conValues(1)
> ''</Example>
> ''******************************Author, Creation & Modification
> Details***************************
> ''* Created By : Shalabh Dixit
> ''* Date Created : 25-June-2011
> ''* Called From (Action Name) : <Action Name Comes Here>
> ''* Last Updated By : Shalabh
> Dixit
> ''* Last Date Updated : 25th June 2011
> ''<Changelog>
>
> ''-------------------------------------------------------------------------------------------------------------------------
> ''S.No. Date Author
> Changes/Notes
>
> ''-------------------------------------------------------------------------------------------------------------------------
>
> '' 1. 25-June-2011 Shalabh Dixit
> 1.Added Logic For Database Connection and
> ''
> Retrieving Data From Database Table.
>
> ''-------------------------------------------------------------------------------------------------------------------------
> ''</Changelog>
> ''</Function>
>
> '''''*************************************************************************************************************************************************************************************************************
> Function ConnectDatabase(Byval strConName,Byval strDSNName,Byval
> strServerName,Byval strDataBaseName,Byval strUserID,Byval strPassword)
> 'Assign Database Connection Information to the DB Variables
> DataSource = strDSNName
> Server = strServerName
> UserID_DB = strUserID
> Password_DB = strPassword
> DatabaseName_DB = strDataBaseName
> con=strConName
> Dim connItems(2)
> Dim connState
>
> 'Declare Database Recordset variable
> conString =
> cstr("DSN="&DataSource&chr(59)&"Server="&Server&chr(59)&"UID="&UserID_DB&chr(59)&"Password="&Password_DB&chr(59)&"DATABASE="&DatabaseName_DB)
>
> 'conn.Open
> "DSN=EPM_DSN;Server=192.168.14.198;UID=EPM;Password=EPM;DATABASE=EPM"
> Set conn = CreateObject("Adodb.Connection")
> 'Open Database Connection
> conn.Open conString
> 'Verify the Successful Database Connection Establishment
> If conn.State=1 Then
> Reporter.ReportEvent micDone,"Database Connection Success","
> Database connection for "&DatabaseName_DB &"Database has been established
> Successfully"
> 'MsgBox "Connection Estblished Successfully"
> Else
> Reporter.ReportEvent micDone,"Database Connection Failure","
> Database connection for "&DatabaseName_DB &"Database is not been established
> successfully"
> 'MsgBox "Connection Not Estblished"
> End If
> connItems(0) = conn.State
> connItems(1) = conn
> ConnectDatabase = connItems
> 'Releasing Memory Allocated to Arrays
> '<Code comes here>
> End Function
>
>
> Regards
> Shalabh Dixit
>
>
>
> On Thu, Jul 21, 2011 at 3:37 PM, Bhuvan Sundar
> <[email protected]<http://mc/[email protected]>
> > wrote:
>
> Before connect to DB, shoul follow below points.
> 1. update the TNS names file with HOSTname,Address,PORT number and Service
> name at location c:\app\product\Network\admin\TNSnames.ORA(file)
> 2. Check the DB connection in Control Panel.
> Thanks,
> Bhuvan
>
> On Thu, Jul 21, 2011 at 3:12 AM, Kiran Ogeti
> <[email protected]<http://mc/[email protected]>
> > wrote:
>
> I am having hard time to connect database .. it gives numerous errors
> through the code,, also I tried using connection string wizard on QTP, but
> interestingly the text box "Connection string" show blank , does not tell me
> what the prob was
>
> could you suggest connection string with the following info what I have
>
> Host name
> Port
> Service
> Database
> Uid
> Pwd
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to
> [email protected]<http://mc/[email protected]>
> To unsubscribe from this group, send email to
> [email protected]<http://mc/compose?to=mercuryqtp%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to
> [email protected]<http://mc/[email protected]>
> To unsubscribe from this group, send email to
> [email protected]<http://mc/compose?to=mercuryqtp%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en