Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get only schema of stored procedure... Not data, as a result set in my application...
Anyone knows how could i get the schema?

Thanks in advance...
Posted

You need to execute the command and get the schema of SP using SqlDataReader.GetSchemaTable().
Try this:
C#
public static DataTable SchemaReader(string tableName) 
{      
  conn.Open();      
  SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn);
  cmd.CommandType = CommandType.StoredProcedure;      
  SqlDataReader reader = cmd.ExecuteReader();       
  DataTable schema = reader.GetSchemaTable();       
  reader.Close();      
  conn.Close();      
  return schema; 
}


--Amit
 
Share this answer
 
You do not want to call the SP as you may affect some data in the DB.

Instead:

SQL
SELECT * FROM sys.dm_exec_describe_first_result_set ('owner.sprocName', NULL, 0) ;


This returns the result set:

is_hidden
column_ordinal 
name
is_nullable 
system_type_id 
system_type_name    
max_length 
precision 
scale 
collation_name      
user_type_id 
user_type_database  
user_type_schema    
user_type_name      
assembly_qualified_type_name
xml_collection_id 
xml_collection_database
xml_collection_schema  
xml_collection_name    
is_xml_document 
is_case_sensitive 
is_fixed_length_clr_type 
source_server   
source_database 
source_schema   
source_table    
source_column   
is_identity_column 
is_part_of_unique_key 
is_updateable 
is_computed_column 
is_sparse_column_set 
ordinal_in_order_by_list 
order_by_is_descending 
order_by_list_length 
error_number 
error_severity 
error_state 
error_message 
error_type  
error_type_desc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900