asp.net 查询本地excel 获取信息

 string filepath = @"D:\test1.xls";         string sheetname = "Sheet5";          string strConn;    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";    OleDbConnection conn = new OleDbConnection(strConn);    OleDbDataAdapter oada = new OleDbDataAdapter ( "select * from [" + sheetname + "$]", strConn );    DataTable dt = new DataTable();    try {          oada.Fill(dt);//获得datatable

         string sqlmaxstr = "select max(pay_period_join_id) from wh_dom_pay_period_join";          DataTable dtmax = Microsoft.ApplicationBlocks.Data.SqlHelper.QueryTable(    OrderManagement.Web.Config.ConnectionString.GetOredrConnectionString(), sqlmaxstr, "table", null);          int max = Convert.ToInt32(dtmax.Rows[0][0])+1;

         for (int i = 0; i < dt.Rows.Count; i++)          {              string venderid = Convert.ToString(dt.Rows[i][0]);              string paydayscodeid = Convert.ToString(dt.Rows[i][1]);              string payday=Convert.ToString(dt.Rows[i][3]);              string sql = "select * from wh_dom_pay_period_join where vendor_id='" + venderid + "' and pay_days_code_id='" + paydayscodeid + "'";              DataTable dt1 = Microsoft.ApplicationBlocks.Data.SqlHelper.QueryTable(            OrderManagement.Web.Config.ConnectionString.GetOredrConnectionString(), sql, "table", null);              if (dt1.Rows.Count > 0)              { }              else              {                  string sqlstr = "insert into  wh_dom_pay_period_join ([pay_period_join_id],[vendor_id],[pay_days_code_id],[pay_days]) values("+max+",'" + venderid + "','" + paydayscodeid + "','" + payday + "')";                  Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteSql(OrderManagement.Web.Config.ConnectionString.GetOredrConnectionString(), sqlstr);                  max++;              }          }     }     catch( Exception ex) {      }

posted on 2013-08-20 17:10  douqiumiao  阅读(269)  评论(0编辑  收藏  举报