Collect data from table and write to a file
Collect data from table and write to a file
(OP)
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"
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"





RE: Collect data from table and write to a file
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
From here just walk the recordset:
CODE
While Not rs.EOF
'Write out your data here:
...
..
' Move to the next record:
rs.MoveNext
Wend
HTH
Todd
RE: Collect data from table and write to a file
HTH
Todd