Re: .vbs vbscript query a sql server database by AL
AL
Thu Mar 10 15:24:59 CST 2005
Hi Tash,
You can use something similar to this vbscript:
------------------------
Dim db
Dim rs
Set db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db.Open "Provider=SQLOLEDB; Data Source=myservername; Initial
Catalog=mydatabase; User ID=xxxxxx; Password=xxxxxx;"
rs.CursorType = 2
rs.LockType = 3
sSQL="SELECT FullName FROM myTable"
rs.Open sSQL, db
If rs.BOF AND rs.EOF Then
'No records
Else
'Found Records
rs.MoveFirst
Do until rs.EOF = True
msgbox(rs("FullName"))
rs.MoveNext
Loop
End If
db.Close
Set rs = Nothing
Set db = nothing
------------------------
Replace myservername for the database PC name, mydatabase for the database
name, and the username and password as necessary.
On retrieving records, my example above shows a dialog box to view all
returned 'Full Names' from the database.
Hope this helps!
AL
"Tash" <Tash@discussions.microsoft.com> wrote in message
news:6BD40DA1-C8C6-45B3-BEDB-BB90D740A19D@microsoft.com...
> Hi,
> I need to query a database and get one field out "ie full name". Its a
sql
> server 7.0 (I also have the database housed in an 8.0 (2000) database)
>
> Can anyone help with code examples. How to make a connection to a
database
> from a vbscript.
>
> Thanks.