gpt4 book ai didi

c# - 批量复制错误 : The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match

转载 作者:太空狗 更新时间:2023-10-29 23:16:19 24 4
gpt4 key购买 nike

我正在使用 SqlBulkCopy 类执行 SQL 批量复制。我创建的目标表与源表完全相同。它们都具有相同的表名、列名、数据类型甚至相同的排序规则。我还做了sql映射以确保准确性。

我的代码如下:

SqlConnection SourceConnection =  new SqlConnection(SourceConnectionString);
SqlConnection DestinationConnection = new SqlConnection(DestinationConnectionString);

DestinationConnection.Open();
SourceConnection.Open();

SqlCommand commandSourceData = new SqlCommand("SELECT * FROM Requisitions;", SourceConnection);

SqlDataReader reader = commandSourceData.ExecuteReader();

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(DestinationConnection))

{
bulkCopy.DestinationTableName = "Requisitions";


bulkCopy.ColumnMappings.Add("RequisitionId", "RequisitionId");
bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
bulkCopy.ColumnMappings.Add("DateCreated", "DateCreated");
bulkCopy.ColumnMappings.Add("AircraftTailNum", "AircraftTailNum");
bulkCopy.ColumnMappings.Add("JobNumber", "JobNumber");
bulkCopy.ColumnMappings.Add("ShopCode", "ShopCode");
bulkCopy.ColumnMappings.Add("RequestedByName", "RequestedByName");
bulkCopy.ColumnMappings.Add("RequestedById", "RequestedById");
bulkCopy.ColumnMappings.Add("Status", "Status");
bulkCopy.ColumnMappings.Add("IsCancelled", "IsCancelled");
bulkCopy.ColumnMappings.Add("IsProcessed", "IsProcessed");


try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(reader);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{

reader.Close();
}
}

但是,每次我执行我的代码时,我都会收到以下错误:

The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match.

我在互联网上搜索了很多,但没有找到任何解决方案。如果有人帮助我,我将不胜感激。

最佳答案

这样试试

  public DataTable fetchValue()
{
SqlDataAdapter dap=new SqlDataAdapter("SELECT RequisitionId,CreatedBy,DateCreated,AircraftTailNum,JobNumber,ShopCode,RequestedByName,RequestedById,Status,IsCancelled,IsProcessed FROM Requisitions;", cn);
DataSet ds=new();
dap.Fill(ds);
return ds.Tables[0];
}

        DataTable dtgenerate=new DataTable();
dtgenerate=fetchValue();

cn.open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(n))
{
bulkCopy.DestinationTableName = "Requisitions";//DestionTableName
// bulkCopy.ColumnMappings.Add("SourceColumnIndex", "DestinationColumnIndex");
bulkCopy.ColumnMappings.Add("RequisitionId", "RequisitionId");
bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
bulkCopy.ColumnMappings.Add("DateCreated", "DateCreated");
bulkCopy.ColumnMappings.Add("AircraftTailNum", "AircraftTailNum");
bulkCopy.ColumnMappings.Add("JobNumber", "JobNumber");
bulkCopy.ColumnMappings.Add("ShopCode", "ShopCode");
bulkCopy.ColumnMappings.Add("RequestedByName", "RequestedByName");
bulkCopy.ColumnMappings.Add("RequestedById", "RequestedById");
bulkCopy.ColumnMappings.Add("Status", "Status");
bulkCopy.ColumnMappings.Add("IsCancelled", "IsCancelled");
bulkCopy.ColumnMappings.Add("IsProcessed", "IsProcessed");

bulkCopy.WriteToServer(dtgenerate);
}
cn.close();

关于c# - 批量复制错误 : The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13797458/

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