0

C# に DataTable があり、それを SQL CE 4 サーバーに送信したいと考えています。もう少し複雑な点の 1 つは、重複が発生した場合、それを無視して DataTable の次の行に移動する必要があることです。調べてみましたが、多くの情報が CE バージョンの SQL Server では機能しないようです。これを行う効率的な方法は何ですか?

4

2 に答える 2

1

DataTable.Selectメソッドを使用して、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(); 
于 2011-12-20T01:58:43.813 に答える
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"); 
          }  
    }

よろしく

于 2011-12-20T02:03:37.890 に答える