我在C#中有一个DataTable,并希望将它发送到我的SQL CE 4服务器。使其更复杂的一件事是,当它遇到重复时,它应该忽略它并继续前进到DataTable中的下一行。我环顾四周,但我发现很多信息似乎与CE版的CE版本无关。这样做的有效方法是什么?
答案 0 :(得分:1)
使用DataTable.Select
方法
e.g。
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();
答案 1 :(得分:0)
试试这个逻辑。
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");
}
}
此致