har*_*ter 14 c# sqlbulkcopy sql-server-ce
是否可以将SqlBulkcopy与Sql Compact Edition一起使用,例如(*.sdf)文件?
我知道它适用于SQL Server 200 Up,但想检查CE兼容性.
如果没有其他人知道在不使用DataSet的情况下将CSV类型文件放入SQL Server CE的最快方法(请点击这里)?
Ale*_*ini 23
SQL CE不支持BULKCOPY.如果表中有大量行,这是最快的方法; 插入太慢了!
using (SqlCeConnection cn = new SqlCeConnection(yourConnectionString))
{
if (cn.State == ConnectionState.Closed)
cn.Open();
using (SqlCeCommand cmd = new SqlCeCommand())
{
cmd.Connection = cn;
cmd.CommandText = "YourTableName";
cmd.CommandType = CommandType.TableDirect;
using (SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable))
{
SqlCeUpdatableRecord record = rs.CreateRecord();
using (var sr = new System.IO.StreamReader(yourTextFilePath))
{
string line;
while ((line = sr.ReadLine()) != null)
{
int index = 0;
string[] values = line.Split('\t');
//write these lines as many times as the number of columns in the table...
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
rs.Insert(record);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
基准:34370行的表格
带插入:每秒写入38行
这样:每秒写入260行
| 归档时间: |
|
| 查看次数: |
12627 次 |
| 最近记录: |