我的代码中有一个填充的DataTable:
我正在使用sql Server CE 4.0并解决性能问题,我正在使用sqlCeBulkcopy:
sqlCeBulkcopyOptions options = new sqlCeBulkcopyOptions(); options = options |= sqlCeBulkcopyOptions.KeepNulls; // Check for DB duplicates using (sqlCeBulkcopy bc = new sqlCeBulkcopy(strConn,options)) { dt = RemoveDuplicateRows(dt,"Email"); bc.DestinationTableName = "Recipients"; bc.WritetoServer(dt); }
RemoveDuplicateRows将从DataTable中删除重复项,但不会检查数据库中已存在的内容.
解决方法
那么你需要对数据表和现有表格进行调整吗?我不确定sql ce是否支持临时表,我用ms sql做了类似的事情,这里是伪代码
string tmpTableDeFinition = "create table #tmpEmails (...)"; using(var connection = new sqlCeConnection(connectionString)) { //Create temp table var tmpTableCommand = new sqlCeCommand(tmpTableDefiniton,connection); tmpTableCommand.ExecuteNonQuery(); //Bulk copy to the temp table,note that bulk copy run faster if the teble is empty //which is always true in this case... using (var bc = new sqlCeBulkcopy(connection,options)) { bc.DestinationTableName = "#tmpEmails"; bc.WritetoServer(dt); } //Run a sp,that have temp table and original one,and marge as you wish in sql //for sp to compile properly,you would have to copy tmp table to script too var spCommand = new sqlCommand("sp_MargeTempEmailsWithOriginal",connection); spCommand.Type = SP //Don't remember exact prop name and enum value spCommand.ExecuteNonQuery(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。