Micro Focus QTP (UFT) Forums
Issue related to DB connectivity.. - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Issue related to DB connectivity.. (/Thread-Issue-related-to-DB-connectivity)



Issue related to DB connectivity.. - galstar - 08-17-2010

Hi,
Plz find below the code for DB connectivity and help me to resolve the issue...

-----------------------------
'-----------------------* Function to get Price by Mfg part no. *----------------------
Code:
Function Connect_to_db(Byval mfgprt)

Dim cnn,rss
Set cnn = CreateObject("ADODB.Connection")
Set rss = CreateObject("ADODB.recordset")
cnn.ConnectionString = "DSN=QTPDSN;Description=desc;UID=;PWD=;APP=QuickTest Professional;WSID=;DATABASE=;"

cnn.open
rss = cnn.Execute("select  UnitPrice  from dbo.ProductProfilePrices ppp inner join priceprofiles pp on ppp.priceprofileID = pp.priceprofileID and isdefaultprofile = 1 inner join products p on ppp.productID = p.productID where MfPartNumber ='" + mfgprt + "'")
Connect_to_db=rss(0)
End Function
'--------------------------* End Function*--------------------------------------------------------------------------

'------------*GET VALUE OF MFG PART# FROM G.SHEET & SET PRICE OUTPUT VALUE in G.SHEET*-------------
Code:
row_cnt=datatable.getrowcount
for i=1 to row_cnt                                 ' For each row , do following
datatable.getsheet(i)                              ' Read Sheet 1 i.e. Global sheet
a=datatable.value("mfg",1)      'Put value of               MfgPart column from global sheet  to variable 'a'

b=Connect_to_db(a)
msgbox(b)
' Pass value of 'a' i.e. Mfgpart to function 'Connect_to_db' and put the value returned by function (i.e. Price) in variable 'b'
-----------------------------

Now what i want to do is that,while reading value from datasheet or saving value to datasheet i want to use local sheet not the global sheet...So what will be the syntax for that..


a=datatable.value("mfg",1)
what will be teh change in this syntax.
mfg col is in the local datasheet..i have 2-3 local datasheet with diff names.....



Thanks