string sql = "delete from sports_xkmd where id=@id";
SqlCommand comm = new SqlCommand(sql, conn);
i = comm.ExecuteNonQuery();
if (i >= 1)
{
sql = "update sports_kbk set yxrs=yxrs-1 where kcxh=@kcxh";
comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("@kcxh", Convert.ToInt32(str[1]));
comm.ExecuteNonQuery();
}代码的意思是学生删除自己的已选课程,如果删除成功(i=1),那么执行更新语句。
每次选课的时候,count(*)和sum(yxrs)【已选人数】总是差别几个,请问是什么问题。
SqlCommand comm = new SqlCommand(sql, conn);
i = comm.ExecuteNonQuery();
if (i >= 1)
{
sql = "update sports_kbk set yxrs=yxrs-1 where kcxh=@kcxh";
comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("@kcxh", Convert.ToInt32(str[1]));
comm.ExecuteNonQuery();
}代码的意思是学生删除自己的已选课程,如果删除成功(i=1),那么执行更新语句。
每次选课的时候,count(*)和sum(yxrs)【已选人数】总是差别几个,请问是什么问题。
注意程序执行时数据库中的数据与在查询分析器中执行时数据库中的数据一致.
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlTransaction stran = conn.BeginTransaction();
string sql = "...";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conn, stran);
stran.Commit(); //提交
stran.Rollback(); //回滚
自己加一些Try catch进去