实现将excel表内容导入到.mdb格式的acess数据库中:
一、界面如图所示:主要是导入用户的相应信息
http://s13/mw690/001moGu8gy6Mafb981S9c&690
二、主要导入代码:
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.SqlClient;
namespace Data1
{
public
partial class Excel_Info : Form
{
//设置数据库路径 AccessDAO类是自己写的读写数据库内容的类库,后文会有备注
private string accessFilePath =
AccessDAO.Property.accessFilePath;
public Excel_Info()
{
InitializeComponent();
}
//调用界面美化工具IirsSkin对界面进行美化
private void Excel_Info_Load(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "MSN.ssk";
}
//退出
private void bnExit_Click(object sender, EventArgs e)
{
this.Close();
}
//浏览相应excel文件
private void bnBrouse_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;
}
}
//导入access数据库中
private void bnImport_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length == 0)
{
MessageBox.Show("请选择导入数据的Execl文件", "南京星星图");
}
//转换类别未选择的时候
else if (raSend.Checked == false && raReceive.Checked ==
false && raRelation.Checked == false)
{
MessageBox.Show("请选择转换类别","南京星星图");
}
#region excel导入到.mdb发包方表中
if (raSend.Checked == true)
{
try
{
OleDbConnectionStringBuilder connectStringBuilder = new
OleDbConnectionStringBuilder();
connectStringBuilder.DataSource = this.textBox1.Text.Trim();