using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click( sender, EventArgs e)
{
OleDbConnection dbconn;
OleDbCommand cmd = null;
dbconn = new OleDbConnection(@\"provider=microsoft.jet.oledb.4.0; Data Source=E:\\\\software\\\\WindowsFormsApplication2\\\\db.mdb\");
DirectoryInfo folder = new DirectoryInfo(\"E:\\\\software\\\\WindowsFormsApplication2\\\\file\");
foreach(FileInfo file in folder.GetFiles(\"*.xls\"))
{
DataSet dt = ExcelToDS(file.FullName);
int l = dt.Tables[0].Columns.Count;
for (int i = 0; i < l; i++)
{
dbconn.Open();
string s1 = dt.Tables[0].Columns[i].ColumnName.ToString();
string s2 = dt.Tables[0].Rows[0][i].ToString();
string sql = \"insert into ************* values(\'\"+file.Name+\"\',\'\" + s1 + \"\',\'\" + s2 + \"\')\";
cmd = new OleDbCommand(@sql, dbconn);
cmd.ExecuteNonQuery();
cmd.Dispose();
dbconn.Close();
}
}
this.label1.Text = \"OK\";
}
public DataSet ExcelToDS(string Path)
{
string strConn = \"Provider=Microsoft.Jet.OLEDB.4.0;\" + \"Data Source=\" + Path + \";\" + \"Extended Properties=Excel 8.0;\";
OleDbConnection conn2 = new OleDbConnection(strConn);
conn2.Open();
string strExcel = \"\";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = \"select * from [土地总面积$3:4]\";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, \"table1\");
conn2.Close();
return ds;
}
继续阅读与本文标签相同的文章
下一篇 :
微信携手万达推出酒店免押入住
-
走,我们一起让改变发生
2026-05-18栏目: 教程
-
互联网娱乐的风口浪尖下,老虎游戏机该如何选择?
2026-05-18栏目: 教程
-
道屹道:即时聊天APP开发 符合当前的时代潮流
2026-05-18栏目: 教程
-
微软前CEO鲍尔默,会成为下一个库克吗?商业模式错误
2026-05-18栏目: 教程
-
加速4G、5G网络演进 全“芯”展锐出新招
2026-05-18栏目: 教程
