表示层:(页面.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
用for来做 for(int i =0;i<DataGrid.Items.Count;i++) { code.... }
'在一个事务里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
for(int i =0;i<DataGrid.Items.Count;i++)
{
code....
}
dr["companyName"]="NIKE";
dr["customerID"]="NIDE"+dataSet11.Tables["customers"].Rows.Count.ToString();
dataSet11.Tables["customers"].Rows.Add(dr);以上语句在windows form中可以正确执行,并且能正确显示
但是在web form中就不能增加和显示数据。