将Excel的数据导入到SQL 2005现有的表中
来源:互联网 发布:java https post json 编辑:程序博客网 时间:2024/05/22 15:54
我在将Excel的数据导入到SQL的时候老是出现下面的错误:
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'Ad Hoc Distributed Queries' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
消息 7399,级别 16,状态 1,第 1 行
链接服务器 "(null)" 的 OLE DB 访问接口 "MICROSOFT.JET.OLEDB.4.0" 报错。提供程序未给出有关错误的任何信息。
消息 7303,级别 16,状态 1,第 1 行
无法初始化链接服务器 "(null)" 的 OLE DB 访问接口 "MICROSOFT.JET.OLEDB.4.0" 的数据源对象。
我将代码贴出来,望大家帮忙指点一下啊!非常感谢!
/// <summary>
/// 打开文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
ofd.Filter = "Excel 文件(*.xls)|";
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
string filepath = ofd.FileName;
this.textBox1.Text = filepath;
}
public void ExecMothod()
{
string sql = "EXEC sp_configure 'show advanced options', 1 /n GO /n RECONFIGURE /n GO /n "+
" EXEC sp_configure 'Ad Hoc Distributed Queries', 1 /n GO /n RECONFIGURE /n GO /n "+
" INSERT INTO tb_Lot SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=" + this.textBox1.Text.Trim() + "',sheet1$)";
string conStr = "server=.;database=MyTestDB;uid=sa;pwd=123456";
SqlConnection con = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int i= cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("数据导入成功");
}
else
{
MessageBox.Show("Error");
}
con.Close();
}
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + this.textBox1.Text.Trim() + ";";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
DataSet ds = new DataSet();
foreach (DataRow dr in dtSchema.Rows)
{
string table = dr["TABLE_NAME"].ToString();
string strExcel = "SELECT * FROM [" + table + "]";
ds.Tables.Add(table);
OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, conn);
myCommand.Fill(ds, table);
}
ExecMothod();
conn.Close();
//KillProcess();
}
- 将Excel的数据导入到SQL 2005现有的表中
- 将excel记录导入到sqlserver现有表中
- 将Excel表导入到SQL Server 2005 的DB
- 将Excel的数据导入到Sql数据库
- 将Excel表中数据导入到SQL Server 2005中
- 将数据库的数据导入到excel中
- 将Excel中多个sheet的数据导入到SQLSERVER中
- 将Excel文件数据导入数据到SQL数据库中
- 将Excel文件中树状结构的数据导入到MSSQL数据库的表中
- 如何将EXCEL数据导入到SQL数据库中来
- 将数据从EXCEL中导入到SQL SERVER
- 怎样将EXCEL数据导入到sql中
- 怎么将excel中的数据快速导入到SQL中
- 关于如何将Excel数据导入到SQL Server中
- 将含有合并单元格的Excel文档导入到SQL Server表中
- 将sql数据导入到Excel
- 将Excel的数据导入DataGridView中
- 将Excel 数据导入到Sql Server 2005
- 什么年月开的博?忘了!!!!!!!!!!
- 如何压缩带有mdw安全文件机制和密码的的access数据库
- 介绍两种SWING常用的布局
- UML 基本图速查---类图. 对象图. 用例图 .参与者. 依赖关系. 泛化继承关系. 关联.....
- VS2005环境下ASP.NET 2.0连接SQL2005数据库的方法
- 将Excel的数据导入到SQL 2005现有的表中
- VS2005中ReportViewer简单运用
- Excel数字文本混合列导入SQL Server出现的问题&解决办法
- 一份好的商业计划书提纲
- 创建发票同时发送SMARTFORMS格式的E-mail给用户
- Myeclipse和Eclipse的区别
- 概率漫谈
- VS2003 试图运行项目时出错,无法启动调试。没有正确安装调试器。请运行安装程序安装或修复调试器。
- jQuery Times 计时器插件