@Santosh Umarani , Welcome to Microsoft Q&A, based on my test, there is no error for me if you want to copy data from datatable to database.
I make a code example and you could refer to it.
static void Main(string[] args)
{
TestEntities1 test=new TestEntities1();
DataTable table = GetDataTable();
SqlConnection connection = new SqlConnection(test.Database.Connection.ConnectionString);
connection.Open();
using (SqlBulkCopy s = new SqlBulkCopy(connection))
{
//set the table name
s.DestinationTableName = "dbo.LogHistory";
foreach (var column in table.Columns)
s.ColumnMappings.Add(column.ToString(), column.ToString());
s.WriteToServer(table);
}
connection.Close();
}
Result in Database:
Hope this could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.