Solved

Query a SQL server from VBScript

Posted on 2009-07-15
1
824 Views
Last Modified: 2012-05-07
Is it possible to Query a SQL server from VBScript, get the sql server to return a boolean value to the vbscript and then use an if statement in the VBScript to act upon that returned value?
0
Comment
Question by:ict-torquilclark
1 Comment
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
Certainly...some sample code for you - of course, you'll need to adjust it to your criteria
If GetBoolean Then

  'Execute some code for a true return

Else

  'Execute otherwise

End If
 

Function GetBoolean()

Dim conn : Set conn = CreateObject("ADODB.Connection")

strCnx = "Driver={SQL Server];Server=SQL-Server7;Database=MyDatabase;user id=SomeID;password='password';" 'You can also use trusted connection...

conn.Open strCnx

Dim cmd : Set cmd = CreateObject("ADODB.Command")

Set cmd.ActiveConnection = conn
 

Dim rs : Set rs = CreateObject("ADODB.RecordSet")

rs.Open "Select MyBoolean From Table1 Where ValueData = SomeCriteria", conn
 

If Not rs.EOF Then GetBoolean = True

rs.Close

End Function

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now