以下是:我可以使用此代码使用SQL Server CE将数据从SQL Server数据库复制到本地(.sdf
):
Public Sub synctrackingstatus()
connection()
sqltable = New DataTable
adap = New SqlClient.SqlDataAdapter
adap = New SqlClient.SqlDataAdapter("SELECT * from TRACKINGSTATUS", con)
adap.Fill(sqltable)
LoginForm.ProgressBar1.Maximum = sqltable.Rows.Count
For Each trackingstatus As DataRow In sqltable.Rows
branches = trackingstatus.Item("ID")
LoginForm.Update()
sqlconnect()
sqlcom = New SqlServerCe.SqlCeCommand("SELECT * FROM TRACKINGSTATUS where ID = '" & trackingstatus.Item("ID") & "' ", sqlcon)
Dim read As SqlServerCe.SqlCeDataReader = sqlcom.ExecuteReader
If read.Read = True Then
sqlcon.Close()
LoginForm.ProgressBar1.Value += 1
percent = (LoginForm.ProgressBar1.Value / LoginForm.ProgressBar1.Maximum) * 100
LoginForm.loading.Text = percent.ToString("N2") & "%"
sqlconnect()
sqlcom = New SqlServerCe.SqlCeCommand("Update TRACKINGSTATUS set ID =@ID,TrackingStatus=@TrackingStatus where ID = '" & trackingstatus.Item("ID") & "'", sqlcon)
'Username, Password, BranchID, FIRSTNAME, LASTNAME, DESIGNATION, Memo, I
sqlcom.Parameters.AddWithValue("@ID", trackingstatus.Item("ID"))
sqlcom.Parameters.AddWithValue("@TrackingStatus", trackingstatus.Item("TrackingStatus"))
sqlcom.ExecuteNonQuery()
sqlcon.Close()
Else
client = trackingstatus.Item("ID").ToString.Replace(" ", "")
sqlcon.Close()
LoginForm.ProgressBar1.Value += 1
percent = (LoginForm.ProgressBar1.Value / LoginForm.ProgressBar1.Maximum) * 100
LoginForm.loading.Text = percent.ToString("N2") & "%"
sqlconnect()
sqlcom = New SqlServerCe.SqlCeCommand("INSERT INTO TRACKINGSTATUS (ID,TrackingStatus) values (@ID,@TrackingStatus)", sqlcon)
sqlcom.Parameters.AddWithValue("@ID", trackingstatus.Item("ID"))
sqlcom.Parameters.AddWithValue("@TrackingStatus", trackingstatus.Item("TrackingStatus"))
sqlcon.Close()
End If
Next
LoginForm.ProgressBar1.Maximum = 0
LoginForm.ProgressBar1.Value = 0
LoginForm.loading.Text = ""
End Sub
由于for each语句,它逐个获取数据..并且逐个获取它需要一分钟甚至一个小时因为我在SQL Server的每个表中都有数千条数据记录。
我想让它立即复制..
是否有足够快的速度复制它以减少我获取数据的等待时间? :d
=============================================== =================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ErikEJ.SqlCe;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand com = new SqlCommand();
SqlConnection con = new SqlConnection("Data Source=192.168.0.97;Initial Catalog=SALESANDTRACKING;User ID=sa;Password=jrs@morethan50");
// Getting source data
com = new SqlCommand("SELECT * FROM AIRBILLS where DateofAirbill between '2017-08-01' and '2017-10-25'", con);
con.Open();
SqlDataReader rdr = com.ExecuteReader();
// Initializing an SqlBulkCopy object
SqlBulkCopy sbc = new SqlBulkCopy("Data Source=localhost;Initial Catalog=AIRBILLS;Integrated Security=True");
// Copying data to destination
sbc.ColumnMappings.Add("ID", "ID");
sbc.ColumnMappings.Add("Sender", "AIRBILL");
sbc.DestinationTableName = "Airbills";
sbc.BulkCopyTimeout = 60;
sbc.WriteToServer(rdr);
// Closing connection and the others
sbc.Close();
rdr.Close();
con.Close();
MessageBox.Show("Database Copied");
}
private static void DoBulkCopy(bool keepNulls, IDataReader reader)
{
SqlCeBulkCopyOptions option = new SqlCeBulkCopyOptions();
if (keepNulls)
{
options = options |= SqlCeBulkCopyOptions.KeepNulls;
}
using (SqlCeBulkCopy bc = new SqlCeBulkCopy(@"Data Source=C:\Users\REGIME\Desktop\WindowsFormsApplication1\Database1.sdf", options))
{
bc.DestinationTableName = "Airbills";
bc.WriteToServer(reader);
}
}
}
}
我到目前为止更新了我的代码..我可以使用EricEJ.SqlCe
但是在我放置该命名空间并更改connectionstring
之后发生了以下错误
Error 38 Ambiguity between 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 102 68 WindowsFormsApplication1
Error 41 Ambiguity between 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 114 162 WindowsFormsApplication1
Error 61 Ambiguity between 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.ColumnName' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 227 33 WindowsFormsApplication1
Error 39 Ambiguity between 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.HasDefault' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.HasDefault' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 111 52 WindowsFormsApplication1
Error 40 Ambiguity between 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.IsNullable' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.IsNullable' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 111 95 WindowsFormsApplication1
Error 59 Ambiguity between 'ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter.FieldCount' and 'ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter.FieldCount' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 215 59 WindowsFormsApplication1
Error 27 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopy.DestinationTableName' and 'ErikEJ.SqlCe.SqlCeBulkCopy.DestinationTableName' C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 67 20 WindowsFormsApplication1
Error 46 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 135 51 WindowsFormsApplication1
Error 52 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 174 96 WindowsFormsApplication1
Error 53 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationColumn' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 178 69 WindowsFormsApplication1
Error 54 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 189 37 WindowsFormsApplication1
Error 55 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 189 71 WindowsFormsApplication1
Error 56 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 191 72 WindowsFormsApplication1
Error 57 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.DestinationOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 193 45 WindowsFormsApplication1
Error 45 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceColumn' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceColumn' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 134 53 WindowsFormsApplication1
Error 47 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceColumn' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceColumn' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 144 107 WindowsFormsApplication1
Error 48 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 150 37 WindowsFormsApplication1
Error 49 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 150 66 WindowsFormsApplication1
Error 50 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 151 99 WindowsFormsApplication1
Error 51 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SourceOrdinal' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 153 47 WindowsFormsApplication1
Error 25 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyOptions.KeepNulls' and 'ErikEJ.SqlCe.SqlCeBulkCopyOptions.KeepNulls' C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 63 59 WindowsFormsApplication1
Error 33 Ambiguity between 'ErikEJ.SqlCe.SqlCeBulkCopyOptions.KeepNulls' and 'ErikEJ.SqlCe.SqlCeBulkCopyOptions.KeepNulls' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 82 89 WindowsFormsApplication1
Error 36 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.GetDataForTable(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.GetDataForTable(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 87 34 WindowsFormsApplication1
Error 43 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.GetDataForTable(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' and 'ErikEJ.SqlCe.DestinationTableDefaultMetadata.GetDataForTable(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 130 49 WindowsFormsApplication1
Error 60 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter.FieldName(int)' and 'ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter.FieldName(int)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 217 35 WindowsFormsApplication1
Error 28 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopy.WriteToServer(System.Data.IDataReader)' and 'ErikEJ.SqlCe.SqlCeBulkCopy.WriteToServer(System.Data.IDataReader)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 68 17 WindowsFormsApplication1
Error 30 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(int, int)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(int, int)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 35 22 WindowsFormsApplication1
Error 31 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(int, string)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(int, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 45 22 WindowsFormsApplication1
Error 32 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(string, int)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(string, int)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 55 22 WindowsFormsApplication1
Error 29 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(string, string)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMapping.SqlCeBulkCopyColumnMapping(string, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 25 22 WindowsFormsApplication1
Error 58 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.Create(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter, ErikEJ.SqlCe.SqlCeBulkCopyOptions, string)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.Create(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter, ErikEJ.SqlCe.SqlCeBulkCopyOptions, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 207 24 WindowsFormsApplication1
Error 37 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.GetSourceColumns(ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.GetSourceColumns(ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 97 33 WindowsFormsApplication1
Error 42 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.GetSourceColumns(ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.GetSourceColumns(ErikEJ.SqlCe.ISqlCeBulkCopyInsertAdapter)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 129 37 WindowsFormsApplication1
Error 44 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.ToColumnNames(System.Collections.Generic.List<ErikEJ.SqlCe.DestinationTableDefaultMetadata>)' and 'ErikEJ.SqlCe.SqlCeBulkCopyColumnMappingCollection.ToColumnNames(System.Collections.Generic.List<ErikEJ.SqlCe.DestinationTableDefaultMetadata>)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 130 35 WindowsFormsApplication1
Error 35 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyTableHelpers.IdentityOrdinal(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' and 'ErikEJ.SqlCe.SqlCeBulkCopyTableHelpers.IdentityOrdinal(System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe.SqlCeTransaction, string)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 85 29 WindowsFormsApplication1
Error 34 The call is ambiguous between the following methods or properties: 'ErikEJ.SqlCe.SqlCeBulkCopyTableHelpers.IsCopyOption(ErikEJ.SqlCe.SqlCeBulkCopyOptions, ErikEJ.SqlCe.SqlCeBulkCopyOptions)' and 'ErikEJ.SqlCe.SqlCeBulkCopyTableHelpers.IsCopyOption(ErikEJ.SqlCe.SqlCeBulkCopyOptions, ErikEJ.SqlCe.SqlCeBulkCopyOptions)' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 82 29 WindowsFormsApplication1
Error 23 The name 'options' does not exist in the current context C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 63 17 WindowsFormsApplication1
Error 24 The name 'options' does not exist in the current context C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 63 27 WindowsFormsApplication1
Error 26 The name 'options' does not exist in the current context C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 65 136 WindowsFormsApplication1
Error 3 The namespace 'ErikEJ.SqlCe' already contains a definition for 'AdoNetUtils' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\AdoNetUtils.cs 6 24 WindowsFormsApplication1
Error 4 The namespace 'ErikEJ.SqlCe' already contains a definition for 'AdoNetUtils' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\AdoNetUtils(2).cs 6 24 WindowsFormsApplication1
Error 11 The namespace 'ErikEJ.SqlCe' already contains a definition for 'DestinationTableDefaultMetadata' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\DestinationTableDefaultMetadata(2).cs 9 24 WindowsFormsApplication1
Error 12 The namespace 'ErikEJ.SqlCe' already contains a definition for 'DestinationTableDefaultMetadata' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\DestinationTableDefaultMetadata.cs 9 24 WindowsFormsApplication1
Error 5 The namespace 'ErikEJ.SqlCe' already contains a definition for 'ISqlCeBulkCopyInsertAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\ISqlCeBulkCopyInsertAdapter.cs 6 24 WindowsFormsApplication1
Error 6 The namespace 'ErikEJ.SqlCe' already contains a definition for 'ISqlCeBulkCopyInsertAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\ISqlCeBulkCopyInsertAdapter.cs 6 24 WindowsFormsApplication1
Error 21 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopy' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopy.cs 19 18 WindowsFormsApplication1
Error 22 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopy' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopy.cs 19 18 WindowsFormsApplication1
Error 13 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyColumnMapping' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyColumnMapping.cs 9 25 WindowsFormsApplication1
Error 14 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyColumnMapping' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyColumnMapping.cs 9 25 WindowsFormsApplication1
Error 19 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyColumnMappingCollection' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyMappingCollection.cs 12 25 WindowsFormsApplication1
Error 20 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyColumnMappingCollection' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyMappingCollection(2).cs 12 25 WindowsFormsApplication1
Error 7 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyDataReaderAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyDataReaderAdapter.cs 6 27 WindowsFormsApplication1
Error 8 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyDataReaderAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyDataReaderAdapter(2).cs 6 27 WindowsFormsApplication1
Error 1 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyDataTableAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyDataTableAdapter(2).cs 6 20 WindowsFormsApplication1
Error 2 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyDataTableAdapter' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyDataTableAdapter.cs 6 20 WindowsFormsApplication1
Error 17 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyOptions' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyOptions.cs 10 17 WindowsFormsApplication1
Error 18 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyOptions' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyOptions(2).cs 10 17 WindowsFormsApplication1
Error 15 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyTableHelpers' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\SqlCeBulkCopyTableHelpers.cs 9 27 WindowsFormsApplication1
Error 16 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeBulkCopyTableHelpers' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeBulkCopyTableHelpers.cs 9 27 WindowsFormsApplication1
Error 9 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeRowsCopiedEventArgs' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeRowsCopiedEventArgs(2).cs 9 18 WindowsFormsApplication1
Error 10 The namespace 'ErikEJ.SqlCe' already contains a definition for 'SqlCeRowsCopiedEventArgs' C:\Users\REGIME\Desktop\WindowsFormsApplication1\EricJS\SqlCeBulkCopy-master\src\Backup\SqlCeRowsCopiedEventArgs.cs 9 18 WindowsFormsApplication1
虽然我没有改变你图书馆里的任何东西..
=============================================== ==========
@ErikEJ对不起,如果我向你提出这么多问题,我删除了代码并安装了金块包,然后又出现了另一个问题
Severity Code Description Project File Line
Error Custom tool error: Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown. WindowsFormsApplication1 C:\Users\REGIME\Desktop\WindowsFormsApplication1\Database1DataSet.xsd 1
Error CS1705 Assembly 'ErikEJ.SqlCe40' with identity 'ErikEJ.SqlCe40, Version=2.1.6.14, Culture=neutral, PublicKeyToken=03b0b5a60fec3719' uses 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' which has a higher version than referenced assembly 'System.Data.SqlServerCe' with identity 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' WindowsFormsApplication1 C:\Users\REGIME\Desktop\WindowsFormsApplication1\Form1.cs 35
我使用.NET Framework 4 Client Profile
=============================================== ================
The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.
答案 0 :(得分:0)
不要使用DataTable,它会产生大量不必要的开销,但是通过SqlDataReader从SQL Server获取数据。
然后,您可以使用我的SqlCeBulkCopy库对SQL Compact数据库执行非常快速的INSERT。 (可能要求你使用空表)
使用ErikEJ.SqlCe;
private static void DoBulkCopy(bool keepNulls, IDataReader reader)
{
SqlCeBulkCopyOptions options = new SqlCeBulkCopyOptions();
if (keepNulls)
{
options = options |= SqlCeBulkCopyOptions.KeepNulls;
}
using (SqlCeBulkCopy bc = new SqlCeBulkCopy(connectionString, options))
{
bc.DestinationTableName = "tblDoctor";
bc.WriteToServer(reader);
}
}
此处有更多信息和示例应用:https://github.com/ErikEJ/sqlcebulkcopy