来自存储过程的架构
我有一个过程,我想阅读该过程的架构。为了检索视图架构,我使用此处显示的查询。我想以同样的方式获取存储过程的架构。如何获得?请显示一些语法。
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;
}
如果有任何疑问请询问。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是一个不调用 SP 的答案 - 如果这样做,您可能会无意中影响数据:
这会返回结果集:
This is an answer that does not call the SP - if you do, you may inadvertently affect data:
This returns the result set :
您可以获得有关存储过程参数的信息,但是如果不执行它,SQL Server 就无法告诉您存储过程返回的数据集的结构。由于执行存储过程可能会产生副作用,因此 ADO.NET 没有提供一种方法来告诉您执行存储过程时结果集会是什么样子。此外,结果集可能会根据执行过程时传递给过程的参数而变化。
You could get information about a stored procedure's parameters but, without executing it, SQL Server cannot tell you the structure of the dataset(s) returned by the stored procedure. Since executing a stored procedure can have side effects, ADO.NET doesn't provide a method for telling you what the result set(s) would look like were the stored procedure to be executed. Furthermore, the result set(s) might change depending on the parameters passed to the procedure when it is executed.
我没有清楚地理解你的问题我认为这对你有用
用这个替换你的查询,它会正常工作
I am not getting your question clearly I think this would work with you
Replace your query with this and it will work fine
我创建了各种使用存储过程输出的代码生成器。根据我的经验,如果您使用 null (DbNull.Value) 作为所有参数的值来调用它们,则大多数 SELECT 任何内容的过程都会输出相同的架构。您可以从系统视图中获取参数列表本身,尽管我发现使用 INFORMATION_SCHEMA.PARAMETERS 很方便。
通过在事务中执行该过程并始终回滚,即使您不知道该过程的作用,您也可以安全地执行某些内容。
您可能需要一个基本的 GUI 并允许用户修改参数 - 或配置文件或其他方式来为特定过程提供参数值。存储过程可能会根据参数产生具有不同模式的输出,尽管我还没有看到很多这样做的情况。
I've created various code generators that use the output of stored procs. In my experience, most procedures that SELECT anything output their schema just the same if you call them with null (DbNull.Value) as the value for all parameters. You can get the parameter list itself from system views, though I find it convenient to use INFORMATION_SCHEMA.PARAMETERS.
By executing the procedure in a transaction and always rolling back you can safely execute stuff even when you have no idea what the procedure does.
You'll probably need a basic GUI and allow the user to modify the parameters - or a config file or some other way to provide parameter values for specific procedures. A stored proc may produce output with different schemas depending on the parameters, though I haven't seen many that do.
app.config
:C#读取关键:
执行存储过程:
C# SQL查询:
app.config
:C# read key:
Executing the stored procedure:
C# SQL query:
你可以做
希望这有帮助
you could do
Hope this help