C#和SQL 2005脚本文件问题 [英] C# and SQL 2005 Script file problem

查看:58
本文介绍了C#和SQL 2005脚本文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要处理的.sql脚本文件,并将结果提供给可以加载到列表视图或类似视图中的各种数据集.

我遇到的问题是如何处理脚本文件并使结果持久化.

我的脚本文件执行以下操作:

1.创建几个功能
2.创建一个临时表
3.创建一个SELECT语句,将临时表链接到各种持久表
4.删除以前创建的功能
5.删除临时表

在SQL管理控制台中,结果"窗格显示我需要的数据和结果集.

我已经看到了许多运行脚本的代码示例,但这些示例似乎是在运行脚本文件,可能是某种维护或表创建例程,例如

I have a .sql script file that I want to process and give me the results in a dataset of sorts that I can load into a listview or similar.

The part I am having a problem with is how to process the script file and get the results to persist.

My script file performs the following :

1. CREATES several FUNCTIONS
2. CREATES a temporary table
3. Creates a SELECT statement linking the temporary table to various persisting tables
4. DROPS the previously created FUNCTIONS
5. DROPS the temporary table

In SQL Management console, the Results pane displays the data and the set of results that I require.

I have seen many examples of code that runs a script, but these examples seems to run the script file, perhaps as some kind of maintenance or table creation routine e.g.

server.ConnectionContext.ExecuteNonQuery(script);



我们需要.sql文件为自包含文件,因此运行它的代码不了解其内容,因此尽管我知道我可以分解脚本文件并重新组装以获取所需的文件,但我确实需要一个脚本文件



We need the .sql file to be self-contained so the code running it knows nothing of its’ contents, so while I know I could break down the script file and re-assemble to acquire what I need, I really need one script file to be ran and the results to be accessible for the next part of my routine.

推荐答案

大多数导出的sql脚本中通常都带有GO关键字,因此可以中断将您的大脚本分成块,可以通过ExecuteNonQuery方法执行.
Most exported sql scripts usually have GO keyword in them so you can break your big script into chunks which you can execute via the ExecuteNonQuery method.


这篇关于C#和SQL 2005脚本文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆