Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SP_HELP returning the values in .net

Posted on 2007-04-01
5
Medium Priority
?
1,056 Views
Last Modified: 2008-01-09
OK, im trying to call  sp_help in a query using c# in .net 1.14 (2003). Unfortunetly I only get the first row back....how do I get all the other rows? Its like the reader only returns the first part of sp_help.....

'ConString' is the database connection string, 'table' is the table name

public static void SelectAnythingSPHelp(string ConString, string table ,ref ArrayList d1,ref ArrayList d2,ref ArrayList d3,ref ArrayList d4,ref ArrayList d5,ref ArrayList d6,ref ArrayList d7,ref ArrayList d8,ref ArrayList d9,ref ArrayList d10)
{
      SqlConnection myConnection = new SqlConnection(ConString);
      SqlCommand myCommand = new SqlCommand("sp_help "+table,myConnection);
      myConnection.Open();
      SqlDataReader myReader;
      myReader = myCommand.ExecuteReader();
      while (myReader.Read())
      {
            try{d1.Add(myReader[0].ToString());}catch{}
            try{d2.Add(myReader[1].ToString());}catch{}
            try{d3.Add(myReader[2].ToString());}catch{}
            try{d4.Add(myReader[3].ToString());}catch{}
            try{d5.Add(myReader[4].ToString());}catch{}
            try{d6.Add(myReader[5].ToString());}catch{}
            try{d7.Add(myReader[6].ToString());}catch{}
            try{d8.Add(myReader[7].ToString());}catch{}
            try{d9.Add(myReader[8].ToString());}catch{}
            try{d10.Add(myReader[9].ToString());}catch{}
      }
      myReader.Close();
      myConnection.Close();
      return;
}
0
Comment
Question by:Saber37886661
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 18834414
sp_help returns multiple tables - run it in Query anayser to see.
My GUESS is that you are returning the last one only
0
 
LVL 39

Accepted Solution

by:
appari earned 1200 total points
ID: 18834417
use NextResult method to check if more results exists,try adding another while loop as follows
**may be my syntax is wrong in c sharp
do{
while (myReader.Read())
      {
            try{d1.Add(myReader[0].ToString());}catch{}
            try{d2.Add(myReader[1].ToString());}catch{}
            try{d3.Add(myReader[2].ToString());}catch{}
            try{d4.Add(myReader[3].ToString());}catch{}
            try{d5.Add(myReader[4].ToString());}catch{}
            try{d6.Add(myReader[5].ToString());}catch{}
            try{d7.Add(myReader[6].ToString());}catch{}
            try{d8.Add(myReader[7].ToString());}catch{}
            try{d9.Add(myReader[8].ToString());}catch{}
            try{d10.Add(myReader[9].ToString());}catch{}
      }
}
while(myReader.NextResult())
0
 
LVL 30

Assisted Solution

by:nmcdermaid
nmcdermaid earned 800 total points
ID: 18834419
sp_help returns 7 rowsets. This example shows how to step through recordsets.


http://support.microsoft.com/kb/311274
0
 
LVL 29

Expert Comment

by:QPR
ID: 18834423
You could disect sp_help into an sp of your own?
Or pipe the sp_help results into a temp table and then return * from that.
0
 
LVL 3

Author Comment

by:Saber37886661
ID: 18834506
appari and nmcdermaid both got it right, thanks guys :)
appari got more points because he was first (by 2 minutes). Thanks heaps for the prompt help guys :)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question