Click to See Complete Forum and Search --> : [RESOLVED] Database Size Form


Nate1
11-05-2007, 08:50 PM
Been trying to follow this tutorial
http://www.4guysfromrolla.com/webtech/032906-1.shtml

but the SpaceUsedInfo class isn't included and Im not really sure what hes talking about, he mentions
"In ASP.NET 2.0 you could use the Generics-based List class to accomplish this without needing to create your own custom strongly-typed collection class."


Could I please have a hand with this

Nate1
11-05-2007, 10:14 PM
Okay Well Have column headings appearing through this code, but no row data, which is there because I can display it in a MsgBox(), the exception produced is :

System.Web.HttpException: A data item was not found in the container. The container must either implement IDataItemContainer, or have a property named DataItem. at System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer) at System.Web.UI.WebControls.BoundField.OnDataBindField(



Const SQL As String = "EXEC sp_MSforeachtable @command1=""sp_spaceused '?'"""
Dim myCommand As New SqlCommand(SQL, Connection())
Try


myCommand.Connection.Open()
'Get the results into a SqlDataReader!
Dim myReader As SqlDataReader = myCommand.ExecuteReader()




'Create a new SpaceUsedInfoList instance
Dim suis(50) As SpaceUsedInfo

'For each result set...
Do

'Read in the records in the result set
While myReader.Read

'Create a new SpaceUsedInfo object & populate its values based
'on the values in myReader
Dim sui As New SpaceUsedInfo
'MsgBox(myReader("name").ToString)
sui.Name = myReader("name").ToString
sui.Rows = myReader("rows").ToString
sui.Data = myReader("data").ToString
sui.IndexSize = myReader("index_size").ToString
'Add the SpaceUsedInfo to the collection
suis(1) = sui
End While

'Loop through each result set... NextResult returns False when we've hit the end
Loop While myReader.NextResult

'Close the reader and connection
myReader.Close() : myCommand.Connection.Close()

'Finally, bind the results to the data Web control
'GridView1
GridView1.DataSource = suis
GridView1.DataBind()

Catch ex As Exception
Dim ErrLog As New ErrorLog
ErrLog.Procedure = "GetDatabaseInfo()"
ErrLog.DateRecorded = Now()
ErrLog.Reference = ex.ToString
WriteErrorLog(ErrLog, True)
End Try

Nate1
11-05-2007, 10:28 PM
This works, but would like to now how to use the stored procedure in SQL server (2005) it doesn't like the code given in the tutorial, could I speed this code up anyway?


'Specify the SQL statement to execute, and create the command...
Const SQL As String = "EXEC sp_MSforeachtable @command1=""sp_spaceused '?'"""
Dim myCommand As New SqlCommand(SQL, Connection())
Try


myCommand.Connection.Open()
'Get the results into a SqlDataReader!
Dim myReader As SqlDataReader = myCommand.ExecuteReader()


Dim dt As New DataTable("DatabaseData")

dt.Columns.Add("name")
dt.Columns.Add("rows")
dt.Columns.Add("data")
dt.Columns.Add("index_size")

'Create a new SpaceUsedInfoList instance


'For each result set...
Do

'Read in the records in the result set
While myReader.Read
Dim newRow As DataRow = dt.NewRow()
'Create a new SpaceUsedInfo object & populate its values based
'on the values in myReader
Dim sui As New SpaceUsedInfo
'MsgBox(myReader("name").ToString)
newRow("name") = myReader("name").ToString
newRow("rows") = myReader("rows").ToString
newRow("data") = myReader("data").ToString
newRow("index_size") = myReader("index_size").ToString
'MsgBox(myReader("name").ToString)
dt.Rows.Add(newRow)
'Add the SpaceUsedInfo to the collection

End While

'Loop through each result set... NextResult returns False when we've hit the end
Loop While myReader.NextResult

'Close the reader and connection
myReader.Close() : myCommand.Connection.Close()

'Finally, bind the results to the data Web control
'GridView1
GridView1.DataSource = dt
GridView1.DataBind()



Catch ex As Exception
Dim ErrLog As New ErrorLog
ErrLog.Procedure = "GetDatabaseInfo()"
ErrLog.DateRecorded = Now()
ErrLog.Reference = ex.ToString
WriteErrorLog(ErrLog, True)
End Try