using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["web"].ToString()))
{
cn.Open();
SqlTransaction st = cn.BeginTransaction(); //开启事务
SqlCommand com = new SqlCommand("Update_Vender_Sales", cn);
com.Connection = cn;
com.Transaction = st;
//try
//{
strS = FileUpload1.FileName;
StringBuilder sb = new StringBuilder();
string filename = DateTime.Now.ToString("yyyymmddhhMMss") + FileUpload1.FileName; //获取Execle文件名 DateTime日期函数
string savePath = Server.MapPath(("~\\upfiles\\") + filename);//Server.MapPath 获得虚拟服务器相对路径
FileUpload1.SaveAs(savePath); //SaveAs 将上传的文件内容保存在服务器上
for (int i = 0; i < _Sales.Length; i++)
{
DataSet ds = ExecleDs(savePath, filename, _Sales[i]); //调用自定义方法
DataRow[] dr = ds.Tables[0].Select(); //定义一个DataRow数组
string code = "", cu_name = "";
for (int k = 0; k < int_k; k++)
{
code = dr[k][0].ToString();
//cu_name = dr[i][1].ToString();
SqlParameter[] sp_ = new SqlParameter[2];
sp_[0] = new SqlParameter("@vender_sales", _Sales[i]);
sp_[1] = new SqlParameter("@code", slk_code);
com.Parameters.Clear();
com.CommandType = CommandType.StoredProcedure;
for (int ii = 0; ii < sp_.Length; ii++)
{
com.Parameters.Add(sp_[ii]);
}
com.ExecuteNonQuery();
}
}
st.Commit();
this.Literal1.Text = "<h3>上传成功!</h3>";