Qtp exports data from the database

Source: Internet
Author: User

Qtp exports data from the database to excel

Set objexcel = Createobject ("Excel. application ")
Xlsurl = "C: \ aa.xls"
Objexcel. workbooks. Open (xlsurl)
Set sheetnew = objexcel. Sheets. Item (1) 'Save the content in the database to the sheet 1 Table in Excel.
Set conn = Createobject ("ADODB. Connection ")
Set res = Createobject ("ADODB. recordset ")
Conn. Open "provider = sqloledb.1; Password = password01 !; Persist Security info = true; user id = sa; initial catalog = pcrm2; Data Source = ws-gisgtssts-03 \ paypaltestserver"
Strsql = "select * From rolebase"
Res. Open strsql, Conn, 1, 1

Dim I
I = 1
While not res. EOF
Roleid = res ("roleid"). Value
Name1 = res ("name"). Value
Isdeleted = res ("isdeleted"). Value
Sheetnew. cells (I + 2nd). value = roleid 'starting from row in the Excel table
Sheetnew. cells (I + 1, 2). value = name1
Sheetnew. cells (I + 1, 3). value = isdeleted
I = I + 1
Res. movenext
Wend

Objexcel. activeworkbook. Save
Objexcel. Quit
Set objexcel = nothing
Res. Close
Set res = nothing

Qtp exports data from the database to the able

Set conn = CreateObject("adodb.connection")
set res = createobject("adodb.recordset")
conn.Open "Provider=SQLOLEDB.1;Password=Password01!;Persist Security Info=True;User ID=sa;Initial Catalog=PCRM2;Data Source=ws-gisgtssts-03\paypaltestserver"
strSql = "select * from RoleBase"
res.Open strSql,conn,1,1

Dim i
i = 1
While not res.EOF
roleID = res("RoleId").value
name1 = res("Name").value
IsDeleted = res("IsDeleted").value
DataTable.LocalSheet.GetParameter("RoleId").ValueByRow(i) = roleID
DataTable.LocalSheet.GetParameter("Name").ValueByRow(i) = name1
DataTable.LocalSheet.GetParameter("IsDeleted").ValueByRow(i) = IsDeleted
i = i + 1
res.MoveNext
Wend

res.Close
Set res = nothing

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.