[英]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.