How to set a DB connection and to get a value from an "adodb" Data Base
Public Function DBSelect
set conn = createobject("adodb.connection")
conn.open "DSN=DSN_SERVERhere; UserID=userID; Password=password;"
set rs = createobject("adodb.recordset")
'get the date value from DB for an Event
rs.open "SELECT searchColumnHere FROM tableName WHERE columnName='value'", conn
eventsInDB = rs("searchColumnHere")
'eventsInDB = FormatNumber(eventsInDB, 2) - use this if you need to format the output nr
rs.close
DBSelect = eventsInDB 'here we are defining the output value
End Function
Or, if the query is defined somewhere outside, for e.g.:
getCol1data = UCASE("SELECT 'searchColumnHere' FROM tableName WHERE columnName='value'") '"searchColumnHere" is the code name of the column which's value should be outputed. for e.g: CLBVAS (use from your select)
then the function can be wrote like this (I've added it within a class):
Public Function DBQuery
DBQuery = New Query
End Function
Class Query
Public Function DBSelect(sqlSelect, searchColumnHere)
set conn = createobject("adodb.connection")
conn.open "DSN=DSN_SERVERhere; UserID=userID; Password=password;"
set rs = createobject("adodb.recordset")
'get the date value from DB for an Event
rs.open sqlSelect, conn
eventsInDB = rs(searchColumnHere)
'eventsInDB = FormatNumber(eventsInDB, 2) - use this if you need to format the output number
rs.close
DBSelect = eventsInDB 'here we are defining the output value
End Function
End Class
now the function is called like this:
DBQuery.DBSelect getCol1data "searchColumnHere" 'the "getCol1data" has the value assigned to it upper
or:
DBSelect getCol1data "searchColumnHere" 'when there is no class defined
try to change your template, its giving fell like annoying
ReplyDeletewhat do you mean, it's about making the article more detailed or what?!
ReplyDeleteHow would you change the script to be able to write to DB? e.g. Update table Set column=val where column=val
ReplyDeleteRegards,
Hi Ovidiu, so in my sample I have the "getCol1data" variable which calls a Select in DB:
Delete-->
getCol1data = UCASE("SELECT 'searchColumnHere' FROM tableName WHERE columnName='value'") '"searchColumnHere" is the code name of the column which's value should be outputed. for e.g: CLBVAS (use from your select)
<--
you can use the "Update ..." sql function assigned to your variable instead of my "Select" and it should work well, give it a try and let me know.
Regards!
Your information about qtp is really interesting. Also I want to know the latest new techniques which are implemented in qtp. Can you update it in your website?
ReplyDeleteHello my friend, I would really like to fulfill your request by doing that, but want to sadly tell you that I am not maintaining this web site almost at all anymore...
DeleteThis is mainly because I don't work with QTP (now FTP) for more that 2 years already..
I'm going to try finding some guys on the iNet wishing to become part of editors team for this web site, and I hope that will work.
You may want to be the first to try?!
Its best source for Setting a DB connection to run any queries from QTP
ReplyDeleteBy
Sri Priya ( Web Designing Training in Chennai )
Thanks Priya! I really appreciate it and glad that at the material here (even if there is not much of it) is useful! Enjoy!
DeleteThanks for sharing this informative blog. Recently I did Digital Marketing Training in Chennai at a leading digital marketing company. It's really useful for me to make a bright career.
ReplyDeleteThank you John! I am glad that it still helps.
DeleteHello there,
ReplyDeleteI am attempting to computerize and run SQL questions through QTP.
. Database Utility instrument introduced is TOAD
. Database is Oracle
Question:
a) Do i have to compose 2 association stings, one to join with amphibian and one to database
On the other hand
I can straightforwardly compose an association string that interfaces with the database and run the questions.
b) For whatever be the situation in the above inquiry,
Would anyone be able to give me the settings i have to design in the Administrative Tools - > DNS Settings
furthermore, the association string too ?
Thanks,
QTP Training in Chennai
Jharkhand Labour Department Recruitment 2016
ReplyDeleteThanks for sharing . Will come to visit again.Click here to find more information......
Jharkhand Labour Department Recruitment 2016
ReplyDeleteGood information given by author, Thank you sir .......
Thanks for sharing your ideas. Its really very useful for us.
ReplyDeleteRegards
QTP Training in Chennai
Good post. Thanks for sharing.
ReplyDeleteSeo courses in Chennai
Thanks for Sharing the nice information.. It was very helpful for us.
ReplyDeleteHadoop Training Chennai
Hadoop Training Bangalore