[英]DataTable to SQL CE 4 Server
我在C#中有一個DataTable,想將其發送到我的SQL CE 4服務器。 使事情變得更復雜的一件事是,當遇到重復項時,它應該忽略它,然后移至DataTable的下一行。 我環顧四周,但發現很多信息似乎不適用於SQL Server的CE版本。 什么是有效的方法?
使用DataTable.Select
方法過濾數據表以在上傳之前排除重復的行
例如
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > #1/1/00#"; // you will need logic to remove your duplicates
DataRow[] foundRows;
// Use the Select method to find all rows excluding duplicates
foundRows = table.Select(expression);
// .NET 3.5 onwards
DataTable filteredDataTable = foundRows.copyToDataTable();
試試這個邏輯。
var dt = new DataTable(); //Supposed that this is your DataTable
foreach(DataRow row in dt.Rows)
{
var find = MyFindMethod("Id"); 1. select statement that find if the id is on database
if(find.Rows > 0)
{
//Id exist do nothing
}
else
{
//Id not exist then 2. Do Insert to sql ce id I not exist
MyInsertMethod("Id");
}
}
問候
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.