添加asp.net Execl的操作实现代码

Microsoft Office Excel是一个很好的电子表格应用程序,小编将向您展示添加asp.net Execl的操作实现代码,一起进入下文学习一下吧!

using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; public partial class html_Test_Execl : System.Web.UI.Page ......{ static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("~/html/") + "new.xls;Extended Properties=Excel 8.0;"; protected void Page_Load(object sender, EventArgs e) ......{ } protected void btnADONET_CreateExecle_Click(object sender, EventArgs e) ......{ OleDbConnection cn = new OleDbConnection( connectionString ); cn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = cn; cmd.CommandText = "create table myTable(firstName char(255),lastName char(255))"; cmd.ExecuteNonQuery(); cmd.CommandText = "insert into myTable (firstName,lastName) values('liao','haibing')"; cmd.ExecuteNonQuery(); cmd.CommandText = "insert into myTable(firstName,lastName) values('廖','海兵')"; cmd.ExecuteNonQuery(); cmd.CommandText = "create table myTable2(姓名 char(255) , 住址 char(255))"; cmd.ExecuteNonQuery(); cn.Close(); } protected void btnShowExecl_Content_Click(object sender, EventArgs e) ......{ ShowExeclContent(); } private void ShowExeclContent() ......{ OleDbConnection cn = new OleDbConnection(connectionString); OleDbDataAdapter dda = new OleDbDataAdapter("select * from [myTable]", cn); DataSet ds = new DataSet(); dda.Fill(ds, "myTable"); DataGrid1.DataSource = ds.Tables["myTable"].DefaultView; DataGrid1.DataBind(); } protected void btnInsertExecl_Click(object sender, EventArgs e) ......{ InsertExeclDate(); ShowExeclContent(); } private void InsertExeclDate() ......{ string executeString = "insert into myTable(firstName,lastName)values('" + this.txtFirstName.Text.Trim() + "','" + txtLastName.Text.Trim() + "')"; this.upDate_Insert_Delete_Operator(executeString); } protected void btnUpdateSelect_Click(object sender, EventArgs e) ......{ upDateSelect(this.txtFirstName.Text.Trim(), this.txtLastName.Text.Trim()); ShowExeclContent(); } private void upDateSelect(string firstName,string lastName) ......{ string executeString = "update myTable set lastName = '" + lastName + "' where firstName = '" + firstName + "'"; this.upDate_Insert_Delete_Operator(executeString); } /**//**//**////删除操作进行不了,提示ISAM 不支持在链接表中删除数据。 不知道有没有什么办法可以解决这个问题 protected void btnDelete_Click(object sender, EventArgs e) ......{ Delete(this.txtFirstName.Text.Trim()); ShowExeclContent(); } private void Delete(string firstName) ......{ string executeString = "delete from myTable where firstName = '" + firstName + "'"; this.upDate_Insert_Delete_Operator(executeString); } private void upDate_Insert_Delete_Operator(string executeString) ......{ OleDbConnection cn = new OleDbConnection(connectionString); cn.Open(); OleDbCommand cmd = new OleDbCommand(executeString, cn); cmd.ExecuteNonQuery(); cn.Close(); } } 

 

原文出处:赵斌自媒体 » 添加asp.net Execl的操作实现代码

超级源码专业为您提供超级源码网,源码分享,商业源码,源码分享平台,实用软件,破解软件,培训教程等全网优质资源。
超级源码网 » 添加asp.net Execl的操作实现代码

发表评论

Captcha Code

欢迎您免费注册发布自己的优质资源,利用平台的海量用户流量,获取丰厚销售提成!

立即发布 我的资源