我想写个程序更新数据库中存储过程 比如我从sql2000中存储过程生成的脚本代码,放到文本框中。点按钮后对sql 中 a b c 数据库存储过程更新。现在关键点是怎么在程序中执行脚本代码,没太搞明白。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你把脚本当做sql语句直接执行看看 http://www.knowsky.com/345516.html //当SQL直接执行bool Sqltest() { bool b = false; try { string sql = ""; foreach (string line in TB_ReportSql.Lines) { sql += line + " "; } int k=new WebSqlRequest().ExecuteNonQuery(sql);//执行SQL b = true; } catch { } return b; } 修改存储过程 你在查询分析器里面怎么写脚本就怎么在程序里拼接字符串,然后用ADO.net、SqlCommand 调用ExecuteNonQuery() 方法执行,这样达不到效果么? 还可以使用sqlcmd: private string executeFromSqlCmd(string source, bool isFromFile) { string result = ""; Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.ErrorDialog = true; p.StartInfo.FileName = "sqlcmd.exe"; if (isFromFile) { p.StartInfo.Arguments = "-W -i " + source; } else { p.StartInfo.Arguments = "-W -Q \"" + source + "\""; } p.Start(); result = p.StandardOutput.ReadToEnd(); p.WaitForExit(); return result; } 高分求助正则达人~ 送分 这段代码为什么是这个结果? IList绑定性能问题(急,在线等待) C#导出Word表格,如何重复利用模板表格? 跨越线程调用窗体上的控件问题 作业求助!急!! 紧急:请问datagridview的DataSource如何和bindinglist绑定,并保持前后台数据同步,最好有代码 C#+SQL一个关于datagridview的问题。难啊,高手们来帮帮我吧。 C#中用FlowChart.NET怎样打开Visio图 datatable中有new row added的时候会触发什么事件,急!(C#) 怎么把自定义空间放到panel中
{
bool b = false;
try
{
string sql = "";
foreach (string line in TB_ReportSql.Lines)
{
sql += line + " ";
}
int k=new WebSqlRequest().ExecuteNonQuery(sql);//执行SQL
b = true;
}
catch { }
return b;
}
private string executeFromSqlCmd(string source, bool isFromFile)
{
string result = "";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.ErrorDialog = true;
p.StartInfo.FileName = "sqlcmd.exe";
if (isFromFile)
{
p.StartInfo.Arguments = "-W -i " + source;
}
else
{
p.StartInfo.Arguments = "-W -Q \"" + source + "\"";
}
p.Start();
result = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return result;
}