gpt4 book ai didi

c# - 找不到类型或命名空间名称 'SqlBulkCopy'

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:12 29 4
gpt4 key购买 nike

有人可以帮我解决这个错误吗?这是我的代码:

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 指令或程序集引用?)

-找不到类型或命名空间名称“SqlBulkCopy”(是否缺少 using 指令或程序集引用?)

-找不到类型或 namespace 名称“OleDbConn”(是否缺少 using 指令或程序集引用?)

最佳答案

SqlBulkCopy类属于 System.Data.SqlClient命名空间。将您的代码添加为喜欢的命名空间;

using System.Data.SqlClient;

此命名空间包含在 System.Data.dll

要在 Visual Studio 中添加引用,您可以在解决方案资源管理器中右键单击“引用”,然后单击添加引用

enter image description here

在搜索框中搜索 System.Data,并将顶部结果 System.Data dll 添加到您的解决方案中。

enter image description here

查看有关 How to: Add or Remove References By Using the Add Reference Dialog Box 的更多信息来自 MSDN

关于c# - 找不到类型或命名空间名称 'SqlBulkCopy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14481047/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com