我想在我的解决方案中存储冗长的.sql脚本并以编程方式执行它们.我已经想出如何执行包含我的sql脚本的字符串,但我还没想出如何从存储在解决方案中的文件中读取字符串(例如,在/ Scripts子文件夹下).
Av *_*zur 22
首先,编辑.sql文件的属性,以便将其作为资源嵌入.
然后使用类似于以下代码来检索脚本:
string commandText;
Assembly thisAssembly = Assembly.GetExecutingAssembly();
using (Stream s = thisAssembly.GetManifestResourceStream(
"{project default namespace}.{path in project}.{filename}.sql"))
{
using (StreamReader sr = new StreamReader(s))
{
commandText = sr.ReadToEnd();
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20010 次 |
最近记录: |