有人可以帮助我,请以修复错误。 这是我的代码:类型或命名空间名称“SqlBulkCopy的”找不到
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);
}
错误:
-The类型或命名空间名称bulkCopy“找不到(?是否缺少using指令或程序集引用)
- 无法找到类型或名称空间名称'SqlBulkCopy'(您是否缺少使用指令或程序集引用?)
- 找不到类型或名称空间名称'OleDbConn'(您是否缺少using指令或一个程序集引用? )
你包括使用System.Data.SqlClient的;在你的类定义的顶部? – Matt
错误说明了这一切。无法找到类型,因为您要么缺少'using'指令,要么缺少程序集引用。添加指定正确名称空间的'using'子句,和/或添加适当的程序集引用。如果你将采取一看[文件](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx),你就已经看到了'SqlBulkCopy'class位于'System.Data.dll'程序集的'System.Data.SqlClient'命名空间中。 – CodeCaster
我向你保证,我没有写的东西使用所有... – Nejthe