Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...