PDA

View Full Version : SQL server and VB


mysteryjimbo
16-03-06, 04:54 PM
Hi,

Who can give me the VB code to connect to a SQL DB and get the results of two SELECT COUNT queries.

It'll save me looking it up! The syntax i used in vbscript isnt playing.

I need it so i can publish the results to a running Performance Counter which is logged in 3rd software. Since this package doesnt support vbscript i've had to go this way..... :evil:

thor
16-03-06, 05:00 PM
VB for Very Bad

mysteryjimbo
16-03-06, 05:21 PM
Helpful, buts its only meant as a short term solution until its integrated into the bespoke software.

TSM
16-03-06, 05:33 PM
I only realy know ASP VB not VB per say.

Have a look here.

http://www.freevbcode.com/ShowCode.Asp?ID=1257
http://vijis.sys.virginia.edu/Developers/DBconnect.htm

timwilky
16-03-06, 05:55 PM
vb? sorry i use java and C#.net Don't be so lazy ...look it up

Gnan
17-03-06, 12:41 AM
this should get it into a recordset object in vbscript

set objConnection = createObject("ADODB.Connection")
set objRecordset = createObject("ADODB.Recordset")
objConnection.Open "DSN=<your preconfigured DSN>;"
objRecordset.CursorLocation = 4
objRecordset.Open "SELECT COUNT(colname) FROM YOURTABLE" ,objConnection,3,3
objRecordset.Close
objConnection.Close

TSM
17-03-06, 09:17 AM
VBScript diffrent from proper VB

huge
17-03-06, 02:37 PM
Link to the queries using a data control and view the query through a datagrid

No code needed to do this

(you might need to add these controls)

if you want to take it further recordsets use a load of methods like update, copy, edit, requery etc.

hope this has helped

mysteryjimbo
17-03-06, 03:41 PM
Sorted it! Its been so long since i did any VB "proper" that i'd forgot a few things..... :oops:

I now have two working performance counters monitoring the number of records in two tables. :thumsbup:

Hopefully this monitoring software will log and alert to it automatically like its supposed to!

Gnan
17-03-06, 10:35 PM
tsm, i saw the word vbscript in the post and must have ignored the rest :D the mrs says that to me sometimes - selective hearing? :D :D

mysteryjimbo
18-03-06, 09:02 AM
tsm, i saw the word vbscript in the post and must have ignored the rest :D the mrs says that to me sometimes - selective hearing? :D :D

Its the only way to go for the administrative stuff that i do.