SQL CE 4 Server的数据表
本文关键字:数据表 Server CE SQL | 更新日期: 2023-09-27 18:18:25
我在c#中有一个数据表,并希望将其发送到我的SQL CE 4服务器。使它变得更复杂的一点是,当遇到重复时,它应该忽略它并继续到DataTable中的下一行。我已经环顾四周,但我发现很多信息似乎不与CE版本的SQL Server工作。做这件事的有效方法是什么?
使用DataTable.Select
Method在上传之前过滤您的DataTable以排除重复行
。
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");
}
}
对