0

我想一次将 CSV 数据插入 SQL Server 数据库。我知道BULK INSERT但我只需要选择一些字段。所以我尝试INSERT INTO如下 -

try
{
   OleDbConnection myOleDbConnection = new OleDbConnection("Provider=SQLOLEDB;Data Source=ServerName;Integrated Security=SSPI;Initial Catalog=DBName;User ID=sa;Password=password");

   myOleDbConnection.Open();

   string strSQL = null;
   strSQL = "INSERT INTO " + strTable + "(" + M_ItemCode + "," + M_ItemDesc + "," + M_UOM + ") " + "SELECT " + M_ItemCode + "," + M_ItemDesc + "," + M_UOM + " FROM [Text;DATABASE=E:\temp\\Item.csv]" ;

   OleDbCommand cmd = new OleDbCommand(strSQL, myOleDbConnection);
   return (cmd.ExecuteNonQuery() == 1);
}
catch (Exception ex)
{
    Common.ShowMSGBox(ex.Message, Common.gCompanyTitle, Common.iconError);
    return false;
}

我得到了错误

无效的对象名称“文本;DATABASE=E:\temp\Item.csv”。

我的语法错了吗?

4

0 回答 0