|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Use of undocumented sp_MSforeachtable and MStablespacethe results of MStablespace for every table in a DataTable. The result contains the number of rows and the data space and the index space. This seems to be okay, because dataTable has three columns after executing the code. The problem is, that I get only one row. using ( SqlConnection conn = new SqlConnection(connString) { conn.Open(); SqlCommand cmd = new SqlCommand("sp_MSforeachtable", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@command1","exec sp_MStablespace '?'"); SqlDataAdapter adapter = new SqlDataAdapter( cmd ); DataTable dataTable = new DataTable("Statistics"); adapter.Fill(dataTable); } Thanks for any hints, Hans
Show quote
Hide quote
"Hans-Peter" <haberland***@gmx.at> wrote in message That command will return N different 1-row result sets. The DataAdapter news:b5064435.0411300807.38b3d959@posting.google.com... > What is wrong with the following code? What I want to do is to store > the results of MStablespace for every table in a DataTable. The result > contains the number of rows and the data space and the index space. > This seems to be okay, because dataTable has three columns after > executing the code. The problem is, that I get only one row. > > using ( SqlConnection conn = new SqlConnection(connString) > { > conn.Open(); > SqlCommand cmd = new SqlCommand("sp_MSforeachtable", conn); > cmd.CommandType = CommandType.StoredProcedure; > cmd.Parameters.Add("@command1","exec sp_MStablespace '?'"); > SqlDataAdapter adapter = new SqlDataAdapter( cmd ); > DataTable dataTable = new DataTable("Statistics"); > adapter.Fill(dataTable); > } > will only fill the DataTable with the first result set. Something like: using (SqlDataReader r = cmd.ExecuteReader()) { while (true) { while (r.Read() ) { //manually fill datatable } if (!r.NextResult() ) { break; } } } David
Other interesting topics
Removing rows from a DataTable is VERY slow
Specifying format of DateTime columns read from CSV files DataSet Memory Usage SQLDataReader XML Dataset [BUG?] (2) Update database using stored procedure and OleDbDataAdapter.Update Aborting a thread corrupts my SqlConnection (?) data adapter update using datatable that has MANY changes how to move record forward or backward how to find out my ADO.NET version |
|||||||||||||||||||||||