找不到类型或名称空间名称"SqlBulkCopy" [英] The type or namespace name 'SqlBulkCopy' could not be found
问题描述
有人可以帮助我解决该错误. 这是我的代码:
can someone help me please to fix that error. this is my code :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data;
using Microsoft.ApplicationBlocks.Data;
using System.Configuration;
OleDbConnection ExcelCon = new OleDbConnection();
ExcelCon.ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=C:\\Users\\pc\\Documents\\ExcellTest.xlsx;Extended Properties=\"Excel 12.0;HDR=Yes\"";
SqlConnection SqlCon = new SqlConnection();
SqlCon.ConnectionString = @"workstation id = PC-PC; user id=sa;Password=sapassword; data source=pc-pc; persist security info=True; initial catalog=CleanPayrollTest2";
string sSQLTable = "TestExcell";
string sClearSQL = "DELETE FROM " + sSQLTable;
SqlCommand SqlCmd = new SqlCommand(sClearSQL, SqlCon);
SqlCon.Open();
SqlCmd.ExecuteNonQuery();
SqlCon.Close();
DataTable dtSchema;
dtSchema = ExcelCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
OleDbCommand Command = new OleDbCommand ("select * FROM [" + dtSchema.Rows[0]["TABLE_NAME"].ToString() + "]", ExcelCon);
OleDbDataAdapter da = new OleDbDataAdapter(Command);
DataSet ds = new DataSet ();
da.Fill(ds);
dataGrid1.DataSource = ds.Tables[0];
OleDbDataReader dr = Command.ExecuteReader();
SqlBulkCopy bulkCopy = new SqlBulkCopy(sSqlConnectionString);
bulkCopy.DestinationTableName = sSQLTable;
while (dr.Read())
{
bulkCopy.WriteToServer(dr);
}
错误:
-找不到类型或名称空间名称"bulkCopy"(您是否缺少using指令或程序集引用?)
-The type or namespace name 'bulkCopy' could not be found (are you missing a using directive or an assembly reference?)
-找不到类型或名称空间名称"SqlBulkCopy"(您是否缺少using指令或程序集引用?)
-The type or namespace name 'SqlBulkCopy' could not be found (are you missing a using directive or an assembly reference?)
-找不到类型或名称空间名称'OleDbConn'(您是否缺少using指令或程序集引用?)
-The type or namespace name 'OleDbConn' could not be found (are you missing a using directive or an assembly reference?)
推荐答案
System.Data.SqlClient
名称空间.将您的代码添加为喜欢的命名空间;
SqlBulkCopy
class belongs on System.Data.SqlClient
namespace. Add your code as a namespace it like;
using System.Data.SqlClient;
此命名空间包含在System.Data.dll
要在Visual Studio中添加引用,可以在解决方案资源管理器中右键单击"Reference
",然后单击Add Reference
.
For adding reference in Visual Studio, you can right click "Reference
" in Solution Explorer and click Add Reference
.
在搜索框中搜索System.Data
,然后将顶级结果System.Data
dll添加到您的解决方案中.
Search System.Data
in search box, and Add the top result System.Data
dll to your solution.
查看有关
Check out for more information for How to: Add or Remove References By Using the Add Reference Dialog Box from MSDN.
这篇关于找不到类型或名称空间名称"SqlBulkCopy"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!