asp.net 实现excel导入到数据库
//Excel批量导入到数据库
protected void btnUpload_Click(object sender, EventArgs e)
{
string IsXls = System.IO.Path.GetExtension(UploadExcel.FileName.ToString().ToLower());
if (IsXls != ".xls")
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script type='text/javascript' language='javascript'>alert('只可以选择Excel文件');location.href='EmployeeAddPage.aspx';</script>");
return;//当选择的不是Excel文件时,返回
}
string filePath = UploadExcel.PostedFile.FileName;
string fileName = UploadExcel.FileName;
DataSet ds = ExecleDs (filePath,fileName);
CommonLayer.employeeModel model = new CommonLayer.employeeModel();
DataAcessLayer.employee_infomation addlist = new DataAcessLayer.employee_infomation();
if (ds.Tables[0].Rows.Count > 0)
{
int row = ds.Tables[0].Rows.Count-1;
for (int i = 0; i < ds.Tables[0].Select().Length; i++)
{
&
相关文档:
1.数据连接方式
ASP.NET本身的数据访问ADO.NET不支持对于MySql的连接和查询,但是MySQL官网上均提供了多种ASP.NET连接到MySQL的方式:
(1)ODBC驱动的访问方式:mysql-connector-odbc-5.1.5-win32.msi,ODBC
(2)ADO.NET对于MySQL的访问方式:mysql-connector-net-6.2.2.zip
个人选用的是第二种,感觉方便,和.NET对S ......
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('加入暂存架成功!');</script>");
asp.net简单加密
//using System.Web.Security;
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfig ......
方法一:javascript法 function btnClear() { for(i=0;i /// 清空指定页面上所有的控件内容,包括TextBox,CheckBox,CheckBoxList,RadioButton,RadioButtonList。但是不清 /// 除如ListBox,DropDownList,因为这样的控件值对当前页面来说还可以用,一般这些控件里都是保存的字典数据。 /// Author:Kevin /// 日期:2004-12 ......
string mapho = request["imgpath"];//获取某个页面传过的图片名称
string str1 = Server.MapPath(mapho);//要添加水印的图片
string str2 = Server.MapPath("WaterMark.jpg");//添加的内容图片
System.Drawing.Image bmp = System.Drawing.Image.fromFile(str1);
Graphics gs = Graphics. ......
最近在做一个网站,显示数据时为了方便使用了GridView。虽然GridView显示数据的功能很强也很方便,但它的样式却并不美观。为了使GridView的显示样式美观一些,经常需要设置表头的背景,我总结出的方法如下:
方法一:
在GridView的OnRowDataBound事件中设置背景,代码如下:
protected void GridView1_RowDataBound(ob ......