Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collect data from table and write to a file

Status
Not open for further replies.

uadm26

Computer
Dec 17, 2007
3
Hi,
I need to do a vbscript or a VB that connect to a database, execute a sql statement and send the output to a file. I have the done something so far, but I can't finish it. Can someone help me?

Dim cmd
Dim rs
Dim params
Dim param
Dim ArgObj, sunumber

Set ArgObj = WScript.Arguments
set cn=createobject("ADODB.Connection")
set cmd=createobject("ADODB.Command")
set rs=createobject("ADODB.Recordset")

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("%comspec% /c <Console Command>")

cn.Provider = "SQLOLEDB"
cn.Open "Data Source = xpto", "User", "User"

Set cmd.ActiveConnection = cn
cmd.CommandText = "SELECT (*) FROM CtrlBalcao"
 
Replies continue below

Recommended for you

Hi uadm26,

I'm not a big script guy, but I've done lots of ADO in VB/VBA. You don't need the command stuff, all you need to do is open the recordset:
Code:
rs.Open "Select * From CtrBalcao", cn, adOpenStatic, adLockReadOnly

From here just walk the recordset:
Code:
rs.MoveFirst

While Not rs.EOF
  'Write out your data here:
  ...
  ..
  ' Move to the next record:
  rs.MoveNext
Wend

HTH
Todd
 
Forgot to mention, you may need to change the above code just a bit for script, I haven't done much script at all, the above is for VB/VBA.

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor