protected void Button2_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["test"];
SqlConnection conm = Conn.getConnetion();

if (conm.State.ToString() == "Closed")
{
conm.Open();
}

SqlTransaction str2 = conm.BeginTransaction();
int k = 0;
if (ds.Tables[0].Rows.Count < 1)
{
Response.Write(" ");
return;
}
try
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string sqlStr2 = "insert into Finance(Fdate,Ftime,Fevikind,Fevino,Fjiefang,Fcredit,Fname,Fcountno,Flender,Fremark,Fdetailno,Flag,Fcompare)values";
sqlStr2 += "('" + ds.Tables[0].Rows[0].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[1].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[2].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[3].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[4].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[5].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[6].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[7].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[8].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[9].ToString() + "',";
sqlStr2 += "'" + ds.Tables[0].Rows[10].ToString() + "',";
//sqlStr2 += "'" + ds.Tables[0].Rows[11].ToString() + "',";
//sqlStr2 += "'" + ds.Tables[0].Rows[11].ToString() + "')";
sqlStr2 += "'0')";
SqlCommand cmd2 = new SqlCommand(sqlStr2,conm,str2);
k += cmd2.ExecuteNonQuery();
}
str2.Commit();
}
catch (Exception ex)
{
Response.Write("发生异常,数据已回滚
信息
" + ex.Message);
str2.Rollback();
}

finally
{
Response.Write("上传成功" + k + "条,转到数据比对模块进行数据比对!");
conm.Close();
}
upcomm.Connection.Open();
upcomm.ExecuteNonQuery();
upcomm.Connection.Close();
GridView1.Visible = false;
Button1.Visible = false;
fileId.Visible = false;
}


我最近得到的方法,亲身实践,可以用
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐