Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

VBscript, sql database select and return records 1

Status
Not open for further replies.

intelwizrd

IS-IT--Management
Dec 20, 2002
263
US
I am trying to write a script that perform some basic file operations based on the status of another system. I need to do a select from a table on a sql database and if any results, then i perform some action, if not, i perform another action. i am not very familiar with db interaction with vb. i can try and post some of what i have but forgive me if it doesnt make much sense.

Dim conn
Dim strSQLInProgress
set conn = CreateObject ("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source=xxx.xxx.xxx.xxx; Initial Catalog=dbdatabase;Network=DBMSSOCN;Uid=test;pwd=testing;"

strSQLInProgress = "SELECT COUNT(id) " _
& " FROM tblData " _
& " WHERE var1 = 1 AND var2 = 1 AND var3 = 0"

conn.Execute StrSQLInProgress, NumRunning

wscript.echo "number in progress: " & NumRunning


the value of "NumRunning" is -1. when i check the table in the database, it is 4. what did i do wrong?

----------------------------
Josh
CCNA, MCSE 2003(in progress)
 
You may try something like this:
...
Dim rs
Set rs = CreateObject("ADODB.Recordset")
rs.Open strSQLInProgress, conn
WScript.Echo "number in progress: " & rs(0)
rs.Close
Set rs = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That did it. Thanks for your help. have another question pertaining to the file system object.

i want to move a file from one directory to another. what is the best way to do that? should i use the FSO or execute a batch file to move it?

example of the command in the batch file would be

move e:\temp1\*.txt e:\temp2\


----------------------------
Josh
CCNA, MCSE 2003(in progress)
 
You may have better error handling with the FSO way.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I would use the FSO. Of course I have something of an unhealthy aversion to shelling out to the command line in any programming language.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Ehhh...PHV beat me to it as usual.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
can you point me in the right direction for moving a file with the fso via vb?

----------------------------
Josh
CCNA, MCSE 2003(in progress)
 
Well here is an example in VBScript:

Sub MoveAFile(Drivespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile Drivespec, "c:\windows\desktop\"
End Sub

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top