很简单
(1)定义中间层函数(传入datatable,在一个事务里处理)
(2)处理成功在表示层显示
我这儿有在表示层定义事务,连接传入中间层处理完一笔,在表示层循环的例子

解决方案 »

  1.   

    表示层:(页面.aspx.vb)  
          '在一个事务里Copy查询到的文件以及目录到选定的目录下面
            Dim con As New OleDb.OleDbConnection()
            Dim ObjTran As OleDb.OleDbTransaction      '事务管理对象 
            Dim objPD As New PersonDoc(CType(Application("ConnectionString"), String))
            Dim i As Integer, j As Integer, Intrtn As Int16
            Dim Dstmp As DataSet
            Dim Tr As DataRow        Try
                For i = 0 To Tb_doc.Rows.Count - 1
                    Dstmp = New DataSet()
                    Dstmp = objPD.GetByPk(mDv_Doc.Item(i).Item("Docno"))
                    StrDocArr(0) = ""
      .............................
                    objPD.AddDocCon(StrDocArr, Dstmp.Tables(0).Rows(0).Item("Docdetail"), con, ObjTran)
                Next
                ObjTran.Commit()
                LblErrMag.Text = "复制成功"
                LblErrMag.ForeColor = Color.FromArgb(0, 0, 255)
            Catch E As Exception
                ObjTran.Rollback()
                LblErrMag.Text = "复制失败"
                LblErrMag.ForeColor = Color.FromArgb(255, 0, 0)
            Finally
                If Not (con Is Nothing) Then
                    If Not (con.State = ConnectionState.Closed) Then
                        con.Close()
                    End If
                End If
            End Try中间层函数:
    public string AddDocCon(string[] VAstradd,byte[] VbyteFile,OleDbConnection VobjCn,OleDbTransaction VObjTran)
    {
    if(mcnStr == "")//连接字符串为空,则抛出错误
    {
    throw(new ArgumentNullException("ConnectionString","数据库连接字符串为空"));
    } OleDbCommand objCmd;
    OleDbCommand objCmdQry;

    objCmd = new OleDbCommand();
    objCmd.Connection = VobjCn;
    objCmd.CommandType=CommandType.Text;
    objCmd.Transaction =VObjTran; //***********增加记录*************
    try
    {
    objCmd.CommandText="insert into PersonDoc .....;
    objCmd.ExecuteNonQuery(); 
    return IntMaxID.ToString();
    }
    catch(OleDbException dbErr)
    {
    throw(dbErr);
    }
    catch  (Exception e)
    {
    throw(new Exception("方法ccccc中发生错误", e));
    }
    }//end of the method AddDocCon
      

  2.   

    用for来做
    for(int i =0;i<DataGrid.Items.Count;i++)
    {
      code....
    }
      

  3.   

    补充一点:一个Webform,有一个绑定的Datagrid作显示数据用,另外,有一个TextBox和两个Button-<btnAdd>,<btnNew>,要求:点击<btnAdd>,将TextBox中的数据加入到Dataset中,并且通过DataGrid显示出,点击<btnAdd>,加入多条数据,最后,按<btnSave>将数据一次性提交到数据库中!
      

  4.   

    DataRow dr= dataSet11.Tables["customers"].NewRow();
    dr["companyName"]="NIKE";
    dr["customerID"]="NIDE"+dataSet11.Tables["customers"].Rows.Count.ToString();
    dataSet11.Tables["customers"].Rows.Add(dr);以上语句在windows form中可以正确执行,并且能正确显示
    但是在web form中就不能增加和显示数据。