string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["OTDB"].ToString();
OleDbConnection con = new OleDbConnection(connStr);
con.Open();
OleDbTransaction st = con.BeginTransaction();
OleDbCommand cmd = con.CreateCommand();
cmd.Transaction = st;
try
{
cmd.CommandText = "delete ID from News where id=" + GridView1.DataKeys[e.RowIndex].Value.ToString() + " ";
cmd.ExecuteNonQuery();
cmd.CommandText = "delete NID from dbo_Fc_CompanyNews new_class_id=" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "";
cmd.ExecuteNonQuery();
st.Commit();
Response.Write("<script>alert('删除成功!');location='NewsTypeManager.aspx'</script>");
}
catch (Exception ee)
{
st.Rollback();
Response.Write("<script>alert('删除失败!');location='NewsTypeManager.aspx'</script>");
}
/////////////////////////
感到语法和数据库语句都没错怎么st.commit()不执行?
OleDbConnection con = new OleDbConnection(connStr);
con.Open();
OleDbTransaction st = con.BeginTransaction();
OleDbCommand cmd = con.CreateCommand();
cmd.Transaction = st;
try
{
cmd.CommandText = "delete ID from News where id=" + GridView1.DataKeys[e.RowIndex].Value.ToString() + " ";
cmd.ExecuteNonQuery();
cmd.CommandText = "delete NID from dbo_Fc_CompanyNews new_class_id=" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "";
cmd.ExecuteNonQuery();
st.Commit();
Response.Write("<script>alert('删除成功!');location='NewsTypeManager.aspx'</script>");
}
catch (Exception ee)
{
st.Rollback();
Response.Write("<script>alert('删除失败!');location='NewsTypeManager.aspx'</script>");
}
/////////////////////////
感到语法和数据库语句都没错怎么st.commit()不执行?
解决方案 »
- 请问怎么写一个为的!=和==
- C# OLEDB 读取EXCEL的奇怪问题~~数字读不出来。。。。。。??
- 高分求一关系函数
- 请问如何安全的销毁线程
- 高难度题!请教
- 如何查询非本机sql server服务器(有用户名密码)的Folder,用folderbrowserDialog好像不行
- 大家帮帮我。。。。动态生成imagebutton的问题
- 求教!!!windowsForm中的问题!
- VPF中用宏代换只要5行代码就能实现的功能在C#中要几百行代码???各位有什么好的招?
- C#的一个缺陷?
- C#除了用控件分页外可否不利用控件比如GRIDVIEW来进行分页?
- 使用RichTextBox控件,如何控制它的翻页操作?
我以前也遇到过这样的 好象是sql 写错了
再不行,改成
cmd.CommandText = "delete ID from News where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
应该为delete from News where id
正如楼上所说,去查询分析器里面执行一下就可以了,应该是sql语句的问题