troubleshooting Question

Getting VBS to query SQL with variable.

Avatar of FMR-Net
FMR-Net asked on
Microsoft SQL ServerVB Script
3 Comments1 Solution4075 ViewsLast Modified:
Im having some problems getting vbscript behave like I want it to. The parts I have done, don't even behave as I want (or expected them to.
Below is my script. What I thought would happen, was that it would query the database. and tell me all entires in the users table. However, what it actually does, is it tells me the firstname of the first entry in the table.
However, what I really want, just don't how to do, is to use the SearchFor variable in a WHERE clause, so the userinput would actually be a name, and then the script would search for that name... and give back all the results.

Hope someone can help me out here.

SearchFor = inputbox("Enter persons name")

Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=SQLNCLI10.1;Integrated Security=SSPI;Initial Catalog=TestDatabase;Data Source=(local);"
conn.Open
WScript.Echo "Connected"

SQL = "select firstname, lastname from TestDatabase.dbo.members"
Set rs = conn.Execute(SQL)
wscript.Echo rs("firstname")

conn.Close
WScript.Echo "connection closed"


(I'm using MS SQL Server)
ASKER CERTIFIED SOLUTION
Joe Howard

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros