Skip to main content

Read Data From Sql DB

'The name of Server
strCurrentEnv = "MyServername\JaySQL"
'The name of your database:
dbName = "qtpDemo"
'SQL Server connection string(you need to enter your username and password)
strConnection = "DRIVER={SQL SERVER}; Server=" & strCurrentEnv & "; DATABASE="& dbName& ";uid=sa; pwd="
Set conn = CreateObject("ADODB.Connection")
conn.Open strConnection
'The SQL you want to run
query = "Select * from dbo.hpTools"
Set rs = conn.Execute(query)
dbResults = rs.GetString
print dbResults

Comments

Popular posts from this blog

Convert JSON to XML using QTP/UFT/VBScript

Sample Code : Dim strPage,strJSON,objIE strPage = "C:\Jay\JLoader.html" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate2 strPage While objIE.Busy : Wend strJSON = "{""FirstName"":""Jay"", ""LastName"":""Krishna""}" Set objWin = objIE.document.parentWindow objWin.execScript "var jsonStr2XML = function(strJSON) { return json2xml(JSON.parse(strJSON));};" Msgbox  oWin.jsonStr2XML(strJSON) objIE.Quit In Detail: Converting The most popular data interchange format JSON(JavaScript Object Notation) to XML using QTP/UFT. Parsing JSON in UFT could be a challenge so we will use JavaScript in UFT to make it perfect. SO We need :              Java Script API  - To Convert JSON to XML                         JavaScript Files :  ...

How to convert Excel column numbers into alphabetical characters

 The ConvertToLetter function works by using the following algorithm: Divide the column number by 27, and then put the resulting integer in the variable "i". Subtract the column number from "i" multiplied by 26, and then put the result in the variable "j". Convert the integer values into their corresponding alphabetical characters, "i" and "j" will range from 0 to 26 respectively. For example: The column number is 30. The column number is divided by 27: 30 / 27 = 1.1111, rounded down by the Int function to "1". i = 1 Next Column number - (i * 26) = 30 -(1 * 26) = 30 - 26 = 4. j = 4 Convert the values to alphabetical characters separately, i = 1 = "A" j = 4 = "D" Combined together, they form the column designator "AD". The following VBA function is just one way to convert column number values into their equivalent alphabetical charac...

QTP defalut Functions

Functions:   Abs Function Returns the absolute value of a number. Abs( number ) The number argument can be any valid numeric expression. If number contains Null, Null is returned; if it is an uninitialized variable, zero is returned. Remarks The absolute value of a number is its unsigned magnitude. For example, Abs( -1 ) and Abs( 1 ) both return 1. The following example uses the Abs function to compute the absolute value of a number: Dim MyNumber MyNumber = Abs( 50.3 )   ' Returns 50.3. MyNumber = Abs( -50.3 ) ' Returns 50.3. Array Function Returns a Variant containing an array. Array( arglist ) The required arglist argument is a comma-delimited list of values that are assigned to the elements of an array contained with the Variant . If no arguments are specified, an array of zero length is created. Remarks The notation used to refer to an element of an array consists of the variable name followed by parentheses containing an index numb...

How To open Password Protected Excel sheets using Vb Script

Function UnprotectXL(filePath,fileName,pwd,writeresPwd)    Set objExcel=CreateObject(“Excel.Application”)    objExcel.Visible=false    testData=filePath&”\”&fileName    Set oWorkbook=objExcel.Workbooks    Set myWkbook=objExcel.Workbooks.open (testData,0,False,5,pwd,writeresPwd)    objExcel.DisplayAlerts=False    oWorkbook(fileName).Activate    For Each w in objExcel.Workbooks         w.SaveAs testData,,”",”"          Next    objExcel.Workbooks.Close    objExcel.Quit    Set oWorkbook=Nothing    Set objExcel=Nothing   End Function Function ProtectXL(filePath,fileName,pwd,writeresPwd)      On Error Resume Next      Set objExcel=CreateObject(“Excel.Application”)      objExcel.Visible=False      testData=filePath...

:: Relative paths in QTP::

=============== Have you ever wondered about how to effortlessly transfer your QTP scripts from your computer to one of colleagues or may be from a drive of your computer to another? Well, relative path is the answer. There can be two types of path in your file System 1. full path or absolute path 2. Relative Path A full path or absolute path is a path that points to the same location on one file system regardless of the working directory. Example of a full path: C:\Program Files\Mercury Interactive\QuickTest Professional\Tests While A relative path is a path relative to the current working directory, so the full absolute path may not need to be given. Example of a relative path: Say your current working directory is QuickTest Professional as shown above so the relative path for the folder Mercury Interactive which is one level up would be..\..\Mercury Interactive similarly folder which is on same level can ...