Search code examples
c#sqlsql-server-2005stored-proceduresado.net

Schema from stored procedure


I have a procedure, I want to read schema of the procedure. To retrieve view schema I use the query shown here. Same way I want to get schema of stored procedure. How to get it? Plz show some syntax.

public static DataTable SchemaReader(string tableName)
{
     string sql = string.Format("Select * from {0}", tableName);
     conn.Open();
     SqlCommand cmd = new SqlCommand(sql, conn);
     cmd.CommandType = CommandType.Text;
     SqlDataReader reader = cmd.ExecuteReader();

     DataTable schema = reader.GetSchemaTable();

     reader.Close();
     conn.Close();
     return schema;
}       

If have any query plz ask.Thanks in advance.


Solution

  • you could do

    public static DataTable SchemaReader(string tableName) 
    {      
      string sql = "MySP";//replace this with your store procedure name      
      conn.Open();      
      SqlCommand cmd = new SqlCommand(sql, conn);
      cmd.CommandType = CommandType.StoredProcedure;      
      SqlDataReader reader = cmd.ExecuteReader();       
      DataTable schema = reader.GetSchemaTable();       
      reader.Close();      
      conn.Close();      
      return schema; 
    }
    

    Hope this help