Exel数据导入到Sql数据库错误 [英] Exel data import to Sql DataBase Error

查看:93
本文介绍了Exel数据导入到Sql数据库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre lang ="cs">字符串excelConnectionString = @&"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\ Deneme.xls;扩展属性=&"& ;"Excel 8.0; HDR = YES;&"&;
使用(OleDbConnection连接=
新的OleDbConnection(excelConnectionString))
{
OleDbCommand命令=新的OleDbCommand
(&选择ID,来自[Sheet1 $]的数据",连接);
connection.Open();
//创建DbDataReader到数据工作表
使用(DbDataReader dr = command.ExecuteReader())
{
//SQL Server连接字符串
字符串sqlConnectionString =";

//批量复制到SQL Server
使用(SqlBulkCopy bulkCopy =
新的SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName =&"ExelData&";
bulkCopy.WriteToServer(dr);
}
}</pre>


我的问题在哪里

错误消息:< pre lang ="msil"> System.Data.SqlClient.SqlException:无效的对象名称&#39; ExelData&#39;.</pre>

但是我的数据库名称是ExelData,这是什么问题

我可以为您提供帮助吗?< b></b>

<pre lang="cs">string excelConnectionString = @&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Deneme.xls;Extended Properties=&quot;&quot;Excel 8.0;HDR=YES;&quot;&quot;&quot;;
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
(&quot;Select id,data FROM [Sheet1$]&quot;, connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "";

// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = &quot;ExelData&quot;;
bulkCopy.WriteToServer(dr);
}
}</pre>


Where is my problem

Error Message:<pre lang="msil">System.Data.SqlClient.SqlException: Invalid object name &#39;ExelData&#39;.</pre>

but my database name is ExelData what is the problem

can I help you<b></b>

推荐答案

&,连接);
connection.Open();
//创建DbDataReader到数据工作表
使用(DbDataReader dr = command.ExecuteReader())
{
//SQL Server连接字符串
字符串sqlConnectionString =";

//批量复制到SQL Server
使用(SqlBulkCopy bulkCopy =
新的SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName =&"ExelData&";
bulkCopy.WriteToServer(dr);
}
}</pre>


我的问题在哪里

错误消息:< pre lang ="msil"> System.Data.SqlClient.SqlException:无效的对象名称&#39; ExelData&#39;.</pre>

但是我的数据库名称是ExelData,这是什么问题

我可以为您提供帮助吗?< b></b>
&quot;, connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "";

// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = &quot;ExelData&quot;;
bulkCopy.WriteToServer(dr);
}
}</pre>


Where is my problem

Error Message:<pre lang="msil">System.Data.SqlClient.SqlException: Invalid object name &#39;ExelData&#39;.</pre>

but my database name is ExelData what is the problem

can I help you<b></b>


请确保
bulkCopy.DestinationTableName


包含您的数据库表名而不是数据库名.

请更正并尝试.


Contains your database table name not a database name.

Correct it and try.


这篇关于Exel数据导入到Sql数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆