在对库中信息操作时,哪种方法处理数据写入并发问题比较好

解决方案 »

  1.   

    我的方法看看,见笑了呵呵
    DataAccess.data dbconn=new DataAccess.data();
    private void Button1_Click(object sender, System.EventArgs e)
    {
    //事务完成标志
    bool bTrans = false;
    try
    {
    this.dbconn.Open();
    this.dbconn.BeginTransaction();
    //事务开始,未完成
    bTrans = false;
    //1插入第一个表string sql ="insert into Send_Info(Car_No) values('008')";
    this.dbconn.moddata(sql);
    Response.Write(sql);
    Response.Write("<br>");
    //2.立即将取出的id插入Goods_List表中
    string sqltext="insert into Goods_List(Car_ID) select top 1car_id from Send_Info order by car_id desc";
    this.dbconn.moddata(sqltext);
    Response.Write(sqltext);
    Response.Write("<br>");this.dbconn.CommitTransaction();
    this.dbconn.Close();
    //事务完成
    bTrans = true; }
    catch
    {
    //异常有可能不是因为事务造成的
    //事务未完成
    if(bTrans == false) 
    {
    //回滚事务
    this.dbconn.RollbackTransaction();
    }
    Response.Write("<script>alert('操作失败')</script>");
    return;
    }Response.Write("<script>alert('操作成功!')</script>");
    }
      

  2.   

    to:flashasp(flashasp) ( )这位仁兄,this.dbconn.BeginTransaction();中BeginTransaction()是哪个对象的方法,我指的是.net框架中的哪个类具有这个方法?
      

  3.   

    lz可查看msdn(输入transation),如果能在数据库利用存储过程+事务来完成的话更好
      

  4.   

    在我的类里面写的哈哈,不好意思忘记发给你拉private System.Data.SqlClient.SqlTransaction transaction;public void BeginTransaction()
    {
    if (!IsOpen)
    throw new System.InvalidOperationException("数据连接没有打开或者已经关闭。");this.transaction = this.conn.BeginTransaction();
    }
    public void  CommitTransaction()
    {
    if (this.transaction == null)
    return;
    this.transaction.Commit();
    this.transaction = null;
    }public void RollbackTransaction()
    {
    if (this.transaction == null)
    return;
    this.transaction.Rollback();
    this.transaction = null;
    }