×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Collect data from table and write to a file

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"

RE: Collect data from table and write to a file

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

RE: Collect data from table and write to a file

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close