Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

has anyone ever tried to get the data from sp_spaceused. I am trying to run just that command in a M$ sql 2000 database. When you run it in query Anaylzer, it has 3 rows returned, then it returns 4 more. when I run the sp and try to stuff it into a datareader, it tells me that there are only 3 rows in the datareader, can anyone tell me how to get all the data from sp_spaceused.

 

   sqlCnT2.Open()
       Dim sqlCMSp_SpaceUsedDb As SqlCommand = New SqlCommand
       With sqlCMSp_SpaceUsedDb
           .Connection = sqlCnT2
           .CommandText = "sp_spaceused"
           .CommandType = CommandType.StoredProcedure
       End With

       'dim dtReaderSp that will be used to hold the info from the sp_spaceused and then put it into the database
       Dim dtReaderSpDb As SqlDataReader = sqlCMSp_SpaceUsedDb.ExecuteReader

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

sorry, i mis-stated what I was trying to get. sp_spaceused give back 1 row in three columns. Then it will bring back four more columns in a second row with three different column headers. How would you navigate that... I'll try to post a result set for you to see. Let's say I'm in the master database and run

 

exec sp_spaceused

 

 

database_name database_size unallocated space

-------------------------- ------------------ ------------------

master 20.63 MB 1.32 MB

 

 

reserved data index_size unused

------------------ ------------------ ------------------ ------------------

16312 KB 11536 KB 1536 KB 3240 KB

 

 

any ideas

JvCoach23

VB.Net newbie

MS Sql Vet

  • Administrators
Posted

The following just simply prints the information in two message boxes - you could just parse the dr.GetString() into variables instead.

Dim dr As SqlClient.SqlDataReader
       Dim conn As New SqlClient.SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=true")
       conn.Open()
       Dim cmd As New SqlClient.SqlCommand
       cmd.Connection = conn
       cmd.CommandType = CommandType.StoredProcedure
       cmd.CommandText = "sp_spaceused"

       dr = cmd.ExecuteReader()

       dr.Read()
       MessageBox.Show(dr.GetString(0) & " " & dr.GetString(1) & " " & dr.GetString(2))
       dr.NextResult()
       dr.Read()
       MessageBox.Show(dr.GetString(0) & " " & dr.GetString(1) & " " & dr.GetString(2) & " " & dr.GetString(3))

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...