Re: Removing duplicate records

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Peter (czupet_at_wsinc.com)
Date: 03/12/04


Date: Fri, 12 Mar 2004 07:44:31 -0600

What is the syntax for the filter?
I want to select only one record

ds.Merge(dsXml.Tables[0].Select("Only first record"));

Thanks

"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:k8$OrRBCEHA.2304@cpmsftngxa06.phx.gbl...
> Hi Peter,
>
> Thank you for posting in the community!
>
> First of all, I would like to confirm my understanding of your issue. From
> your description, I understand that you need to merge the DataSets from
the
> Xml files into one and you need to remove the duplicate rows. If there is
> any misunderstanding, please feel free to let me know.
>
> As far as I know, to remove the duplicate records, we need add a primary
> key to the table. The primary key is for the table to identify a row and
to
> decide whether two records are the same. When merging two DataSets with
> primary key, the method will automatically overwrite the old record with
> new fetched one. So that only one copy of that record will be added.
>
> If there is no primary key set in the table, I think we have to write more
> code to achieve this. We can use the Select method to decide whether the
> records exists in the current DataSet. Here I have made some changes to
> your code.
>
> DataSet ds = new DataSet();
> DataSet dsXml = new DataSet();
>
> try
> {
> string [] files = Directory.GetFiles(path,"VisitTable_*.xml");
> foreach(string file in files)
> {
> dsXml.ReadXml(file, System.Data.XmlReadMode.Auto);
> foreach(DataRow dr in dsXml.Tables[0].Rows)
> {
> if(ds.Tables[0].Select("Filter expression here to decide whether the
> records exists.").Length == 0)
> ds.Tables[0].Rows.Add(dr.ItemArray);
> }
> }
> }
> catch(Exception e)
> {
> throw e;
> }
>
> HTH. If anything is unclear, please feel free to reply to the post.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



Relevant Pages

  • RE: DataTable.RemoveRow
    ... Thank you for posting in the community! ... I would like to confirm my understanding of your issue. ... when you fill a DataTable which has a primary key ... "This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Primary key with or without?
    ... Temporary tables or working tables could be one situation where the creation ... does say that having a primary key is not required in the Ansi SQL Standard! ... John ... > loads from data files with duplicate rows? ...
    (microsoft.public.sqlserver.programming)
  • Re: complex duplicate row
    ... > But how to select duplicate rows (identical in all the columns, ... > codfisc) and in the same time the result also to include this column, ... columns in a table except the primary key could/should be nullable. ... and you don't have a parent row for it, just do an insert into the parent ...
    (comp.databases.informix)
  • RE: Removing duplicate records
    ... I would like to confirm my understanding of your issue. ... Xml files into one and you need to remove the duplicate rows. ... The primary key is for the table to identify a row and to ... "This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: "IDS 10.0 Cities Tour 2006" - Regrettably on topic
    ... I apologize profusely for posting on topic. ... > next post a chauvinistic piece of flame bait or a lengthy quote followed ... columns in a table except the primary key could/should be nullable. ... and you don't have a parent row for it, just do an insert into the parent ...
    (comp.databases.informix)