大伙看看这代码中的事务提交为什么不成功
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()不执行?
------解决方案--------------------cmd.CommandText = "delete NID from dbo_Fc_CompanyNews new_class_id= " + GridView1.DataKeys[e.RowIndex].Value.ToString() + " ";
少了where这句
------解决方案--------------------delete ID from News where id
应该为delete from News where id
正如楼上所说,去查询分析器里面执行一下就可以了,应该是sql语句的问题