Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Assigning a single row of query data to a variable

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,66082
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Assigning a single row of query data to a variable
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Assigning a single row of query data to a variable - 11/7/2008 3:00:17 AM   
  BMF

 

Posts: 1
Score: 0
Joined: 11/7/2008
Status: offline
Hi there, I'm more of a PHP/MySQL guy (wait for booing to stop...) Alright, now that that is out of the way.

I'm doing a very basic query in a VBScript to query the size of a hard disk in a system:

Set diskSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("Select Size, Index From Win32_DiskDrive where Index = 0")

All i need to do is assign diskSet[0][Size] to a variable.

In PHP I would simply do something like:

$dat = mysql_fetch_row($diskSet);
$size = $dat[0];

So far I haven't found a good way to do that in VBScript.

i have been able to pull the data using a FOR loop, but that seems silly considering there is always only going to be a single row.

Anyone have any clue?

thanks,
BMF
 
 
Post #: 1
 
 RE: Assigning a single row of query data to a variable - 11/7/2008 3:49:29 AM   
  buck2825


Posts: 14
Score: 0
Joined: 11/5/2008
Status: offline
Below is some script I use to pull data out of a MSsql 2005 DB and dump it to a Excel spread sheet.  I know its not mysql but i'm not 100% that something along these lines will not work. 
 
 
 
 
'*****************************************************************************************
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
 
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
 
 objConnection.Open "Provider=SQLOLEDB.1;Initial Catalog=database_name;Data Source=computer_name\sql_instance;Persist Security Info=False;user id=sa; password=sa"
 'objConnection.Open "Provider=SQLOLEDB.1;Initial Catalog=database_name;Data Source=computer_name\sql_instance;Persist Security Info=False;Integrated Security=SSPI;" 'use for windows login
 

objRecordset.CursorLocation = adUseClient
 
 
 objRecordset.Open "SELECT * FROM Table", objConnection, adOpenStatic, adLockOptimistic
 
 set excel = createobject("excel.application")
excel.visible = true
excel.workbooks.add
introw = 2
 
 
 if objrecordset.recordcount <> 0 then
 
  objRecordset.movefirst
  do until objRecordset.eof
 excel.cells(introw,1).value = objRecordset.fields("column").value
   
 objRecordset.movenext
 introw = introw+1
loop
 else
  msgbox "No Data"
 end if
objRecordset.Close
objConnection.Close
 


< Message edited by buck2825 -- 11/7/2008 3:51:55 AM >

(in reply to BMF)
 
 
Post #: 2
 
 RE: Assigning a single row of query data to a variable - 11/7/2008 4:04:34 AM   
  dm_4ever


Posts: 2728
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Unfortunately accessing the data in the manner you want is only really available under Windows Vista....there is a way to access certain properties directly depending on the class, but you need to know the value for the primary key for this to work.

i.e.

      

However, is using the For...Loop really that much more work??....especially since you will probably end up using it if you're going to be using VBScript...a few extra lines never hurt anybody


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to BMF)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Assigning a single row of query data to a variable Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts