在.net执行sql脚本的怎么实现 在Text文本中放SQL语句,在。NET怎么去调用他 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlConnect.open();SqlCommand.CommandText=TextBox.Text;SqlCommand.Execuse 1将每一个sql加到ArrayList的对象里2循环ArrayList的对象里的对象,一句一句执行sql语句 public static bool ExeTransactionS(System.Collections.ArrayList o) { string str_path=System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath);// OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings[0]+str_path+System.Configuration.ConfigurationSettings.AppSettings[1]); OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings[0]); con.Open(); OleDbTransaction tran = con.BeginTransaction(); OleDbCommand cmd = con.CreateCommand(); cmd.CommandTimeout=5000; cmd.Transaction = tran; try { for(int i=0;i<o.Count;i++) { cmd.CommandText = o[i].ToString(); cmd.ExecuteNonQuery(); } tran.Commit(); } catch(OleDbException e) { try { tran.Rollback(); } catch (OleDbException ex) { if (tran.Connection != null) { System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('在尝试回滚事务的时候发生" +ex.Message+"错误!请联系管理员维护数据!')</script>"); return false; } } System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('在尝试写入数据的时候发生" +e.Message+"的错误!数据安全!')</script>"); return false; } finally { con.Close(); } return true; } 调用:ArrayList a=new ArrayList();string sql="";//你的sqla.add(sql);sql="";//你的sqla.add(sql); if (ExeTransactionS(conn,a));//conn你的连接字符串{ //成功处理}else{//失败处理} string str = TextBox1.text;.......SqlCommand com = new SqlCommand(str,conn);................. private void CreateDataBase (){Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = false; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; string Path = Application.StartupPath.ToString();string Parameter = "osql.exe -U " + uid + " -P " + pwd + " -S "+ ServerName +" -i " + Path + @"\IPMS.sql";try { this.Cursor = System.Windows.Forms.Cursors.WaitCursor;p.Start(); p.StandardInput.WriteLine(Parameter); p.StandardInput.WriteLine("exit"); p.StandardInput.WriteLine("exit");p.WaitForExit(); p.Close();} catch(Exception e) { MessageBox.Show(e.Message);this.Close();} } 请教页面动态加载控件怎么做呢? asp.net sql语句 重复名字 大二上半年刚结束,前辈来给我指路 关于上传文件的验证和设置的问题,请各位大师帮帮忙哦,谢谢,看如何修改比较好哦 求问 我在Win2003上安装的VS2005 Pro在启动WEB项目后打开文件怎么经常莫名死机? GridView如何在内存里面操作?? 最近一直在忙,asp.net2.0问题(哈哈) 请问有没有这样的.NET(C#版本)书籍? 新网站上线,大家看看,评论评论,以便我总结经验,以后提高,谢谢 怎么才能捕捉到history.go(-1)(后退)这个事件呢?
SqlCommand.CommandText=TextBox.Text;
SqlCommand.Execuse
2循环ArrayList的对象里的对象,一句一句执行sql语句
{
string str_path=System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath);
// OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings[0]+str_path+System.Configuration.ConfigurationSettings.AppSettings[1]);
OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings[0]);
con.Open();
OleDbTransaction tran = con.BeginTransaction();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandTimeout=5000;
cmd.Transaction = tran;
try
{
for(int i=0;i<o.Count;i++)
{
cmd.CommandText = o[i].ToString();
cmd.ExecuteNonQuery();
}
tran.Commit();
}
catch(OleDbException e)
{
try
{
tran.Rollback();
}
catch (OleDbException ex)
{
if (tran.Connection != null)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('在尝试回滚事务的时候发生"
+ex.Message+"错误!请联系管理员维护数据!')</script>");
return false;
}
}
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('在尝试写入数据的时候发生"
+e.Message+"的错误!数据安全!')</script>");
return false;
}
finally
{
con.Close();
}
return true;
}
ArrayList a=new ArrayList();
string sql="";//你的sql
a.add(sql);
sql="";//你的sql
a.add(sql);
if (ExeTransactionS(conn,a));//conn你的连接字符串
{
//成功处理
}
else
{
//失败处理
}
.......
SqlCommand com = new SqlCommand(str,conn);
.................
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string Path = Application.StartupPath.ToString();
string Parameter = "osql.exe -U " + uid + " -P " + pwd + " -S "+ ServerName +" -i " + Path + @"\IPMS.sql";
try
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
p.Start();
p.StandardInput.WriteLine(Parameter);
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
this.Close();
}
}