作者: | 来源:互联网 | 2023-09-18 19:59
数据库|mysql教程Excel,导入,Access,数据库,winForm,直接数据库-mysql教程淘宝客系统源码下载,ubuntu编写c文件,python常用的爬虫,phpc
数据库|mysql教程
Excel,导入,Access,数据库,winForm,直接
数据库-mysql教程
淘宝客系统源码下载,ubuntu编写c文件,python常用的爬虫,php cosedir,杜桥seolzw
直接贴代码吧。 /// summary /// 获取Excel文件 /// /summary /// param name=sender/param /// param name=e/param private void button1_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = Excel文件(*.xls)|
app推广页面源码,Ubuntu下载jdk很慢,软件服务社 tomcat,爬虫战斗姿态,php输出数组变量,白云关键词seo优化多少钱lzw
易语言cf源码大全,怎样关闭vscode打开的文件,ubuntu 插入,tomcat设置项目启动路径,sqlite 创建表单,中文网页设计模板html,万网阿里云云服务器购买,.net ajax 上传图片插件,boot前端框架模板,爬虫调度问题,php语法检查,seo的考核,高并发秒杀springboot,中文社交网站图标,qt获取网页源代码,dz分类信息模板制作,a标签调用后台方法,asp代码有页面吗,仓库管理系统演示,手机影视网站程序lzw
直接贴代码吧。
///
/// 获取Excel文件
/// /// /// private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = “Excel文件(*.xls)|*.xls”;
if (dlg.ShowDialog() == DialogResult.OK)
{
string filePath = dlg.FileName;
this.textBox1.Text = filePath;
}
}
///
/// 导入Excel文件
/// /// /// private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length == 0)
{
MessageBox.Show(“请选择导入数据的Execl文件”);
}
else
{
try
{
OleDbConnectionStringBuilder cOnnectStringBuilder= new OleDbConnectionStringBuilder();
connectStringBuilder.DataSource = this.textBox1.Text.Trim();
connectStringBuilder.Provider = “Microsoft.Jet.OLEDB.4.0”;
connectStringBuilder.Add(“Extended Properties”, “Excel 8.0”);
using (OleDbConnection cn = new OleDbConnection(connectStringBuilder.ConnectionString))
{
DataSet ds = new DataSet();
string sql = “Select * from [Sheet1$]”;
OleDbCommand cmdLiming = new OleDbCommand(sql, cn);
cn.Open();
using (OleDbDataReader drLiming = cmdLiming.ExecuteReader())
{
ds.Load(drLiming, LoadOption.OverwriteChanges, new string[] { “Sheet1” });
DataTable dt = ds.Tables[“Sheet1”];
if (dt.Rows.Count > 0)
{
for (int i = 0; i
{
//写入
数据库数据
string MySql = “insert into ClientInfo values(‘”+dt.Rows[i][“姓名”].ToString()+”‘,'”+dt.Rows[i][“姓名”].ToString()
+”‘,’0’,'”+dt.Rows[i][“备注”].ToString()+”‘,’0’,'”+i.ToString()+”‘)”;
new DataAccess().SQLExecute(MySql);
}
MessageBox.Show(“数据
导入成功!”);
}
else
{
MessageBox.Show(“请检查你的Excel中是否存在数据”);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
///
/// 数据操作通用类
/// /// ///
public bool SQLExecute(string sql)
{
try
{
OleDbConnection cOnn= new OleDbConnection(CONNECT_STRING);
conn.Open();
OleDbCommand comm = new OleDbCommand ();
comm.COnnection= conn;
comm.CommandText = sql;
comm.ExecuteNonQuery();
comm.Connection.Close();
conn.Close();
return true;
}
catch
{
return false;
}
}