欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

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

时间:2020-12-22 17:52:25|栏目:.NET代码|点击:
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();
}
}

上一篇:DevExpress实现TreeList向上递归获取公共父节点的方法

栏    目:.NET代码

下一篇:C# 定时器保活机制引起的内存泄露问题解决

本文标题:asp.net Execl的添加,更新操作实现代码

本文地址:http://www.codeinn.net/misctech/35393.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有