tbaseflug
asked on
Hard Drive Space Values into Datagrid as columns
I am looking to get the hard drives and spaces from my servers and have the below working great to return it via an array - but wanted to do return each value as a column in a datagrid - is this possible and if so how?
--------------------
Private Function SystemList(ByVal strComputer As String) As ArrayList
Dim al2 As New ArrayList
Dim co As ConnectionOptions = New ConnectionOptions()
co.Username = "Nsadm13"
co.Password = "houston"
Dim ms As System.Management.Manageme ntScope = New System.Management.Manageme ntScope("\ \" & strComputer & "\root\cimv2", co)
Dim oq As System.Management.ObjectQu ery = New System.Management.ObjectQu ery("Selec t * from Win32_LogicalDisk where DriveType=3")
Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(m s, oq)
Dim queryCollection1 As ManagementObjectCollection = Query1.Get()
Dim mo As ManagementObject
For Each mo In queryCollection1
al2.Add( _
"<b>Drive</b>: " & mo("Name").ToString() & _
"<br><b>Free Space</b>: " & Data.ConvertBytes(CType(mo ("FreeSpac e").ToStri ng, Long)) & _
"<br><b>Size</b>: " & Data.ConvertBytes(CType(mo ("Size").T oString, Long)) _
)
Next
Return (al2)
End Function
--------------------
Private Function SystemList(ByVal strComputer As String) As ArrayList
Dim al2 As New ArrayList
Dim co As ConnectionOptions = New ConnectionOptions()
co.Username = "Nsadm13"
co.Password = "houston"
Dim ms As System.Management.Manageme
Dim oq As System.Management.ObjectQu
Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(m
Dim queryCollection1 As ManagementObjectCollection
Dim mo As ManagementObject
For Each mo In queryCollection1
al2.Add( _
"<b>Drive</b>: " & mo("Name").ToString() & _
"<br><b>Free Space</b>: " & Data.ConvertBytes(CType(mo
"<br><b>Size</b>: " & Data.ConvertBytes(CType(mo
)
Next
Return (al2)
End Function
Instead of using an arraylist use a datatable
ASKER
Any way that you could show me based upon my code above?
Private Function SystemList(ByVal strComputer As String) As datatable
Dim al2 As New datatable
al2.columns.add("Diskname" , gettype(System.string))
al2.columns.add("FreeSpace ", gettype(System.int32))
al2.columns.add("Size", gettype(System.int32))
Dim co As ConnectionOptions = New ConnectionOptions()
co.Username = "Nsadm13"
co.Password = "houston"
Dim ms As System.Management.Manageme ntScope = New System.Management.Manageme ntScope("\ \" & strComputer & "\root\cimv2", co)
Dim oq As System.Management.ObjectQu ery = New System.Management.ObjectQu ery("Selec t * from Win32_LogicalDisk where DriveType=3")
Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(m s, oq)
Dim queryCollection1 As ManagementObjectCollection = Query1.Get()
Dim mo As ManagementObject
For Each mo In queryCollection1
dim dr as datarows = dt.newrow
dr.item("Diskname") = mo("Name").ToString()
dr.item("FreeSpace") = Data.ConvertBytes(CType(mo ("FreeSpac e").ToStri ng, int32))
dr.item("Size") = Data.ConvertBytes(CType(mo ("Size").T oString, int32))
dt.rows.add(dr)
Next
Return (al2)
End Function
Dim al2 As New datatable
al2.columns.add("Diskname"
al2.columns.add("FreeSpace
al2.columns.add("Size", gettype(System.int32))
Dim co As ConnectionOptions = New ConnectionOptions()
co.Username = "Nsadm13"
co.Password = "houston"
Dim ms As System.Management.Manageme
Dim oq As System.Management.ObjectQu
Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(m
Dim queryCollection1 As ManagementObjectCollection
Dim mo As ManagementObject
For Each mo In queryCollection1
dim dr as datarows = dt.newrow
dr.item("Diskname") = mo("Name").ToString()
dr.item("FreeSpace") = Data.ConvertBytes(CType(mo
dr.item("Size") = Data.ConvertBytes(CType(mo
dt.rows.add(dr)
Next
Return (al2)
End Function
ASKER
RonaldBiemans -
That works great!!! However, is there any way to flip it so that the drives appear across the top as column headers and that the size and space columns are rows under then., e.g.
C D E
--- --- ---
10 15 20
That works great!!! However, is there any way to flip it so that the drives appear across the top as column headers and that the size and space columns are rows under then., e.g.
C D E
--- --- ---
10 15 20
Hmmm, there is but you have to do a bit of cheating, The trick is to transpose your datatable.
Can this wait till tomorrow because I have to leave now, but I can give you the code first thing in the morning
Can this wait till tomorrow because I have to leave now, but I can give you the code first thing in the morning
ASKER
Certainly - I just appreciate the help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
RonaldBiemans -
Wow, that works great!!! You have certainly earned the points. I am going to open another 500 pt question as I have a list of server names coming from my SQL db and am looping through the server names in a datareader and will need to add the server name to the grid as well - you have earned the pts for this one and will certyainly give another 500 if you want to help on the last part of this?
Wow, that works great!!! You have certainly earned the points. I am going to open another 500 pt question as I have a list of server names coming from my SQL db and am looping through the server names in a datareader and will need to add the server name to the grid as well - you have earned the pts for this one and will certyainly give another 500 if you want to help on the last part of this?