日期:2014-05-18 浏览次数:20923 次
protected void ButtonUserOK_Click(object sender, EventArgs e) { string saveDir = @"\Uploads\"; string appPath = Request.PhysicalApplicationPath; if (FileUploadUser.HasFile) { string fileName = Server.HtmlEncode(FileUploadUser.FileName); string extension = System.IO.Path.GetExtension(fileName); if (extension == ".xls") { string savePath = appPath + saveDir + fileName; FileUploadUser.SaveAs(savePath); string ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\教学工作量管理系统.mdf;Integrated Security=True;User Instance=True"; using (SqlConnection conn = new SqlConnection(ConnectionString)) { string sql = "select * into 个人信息表 from opendatasource('Microsoft.Jet.OLEDB.4.0','Data Source=" + savePath + ";Extended Properties=Excel 8.0')...[Sheet1$]"; SqlCommand cmd = new SqlCommand(sql, conn); try { conn.Open(); cmd.ExecuteNonQuery(); Response.Write("<script> window.alert('导入新系部人员信息成功!');</script>"); conn.Close(); } catch (System.Exception ex) { Response.Write("<script> window.alert('导入新系部人员信息失败!出错信息:" + ex.Message + "');</script>"); conn.Close(); } conn.Close(); } } else { Response.Write("<script>window.alert('只能导入EXCEL文件!');</script>"); return; } } else { Response.Write("<script>window.alert('文件数据上传失败!');</script>"); return; } }