PC Review


Reply
Thread Tools Rate Thread

2 questions. Partial SqlDataAdapter.Fill() and ReadXml()

 
 
Jon Brunson
Guest
Posts: n/a
 
      16th Sep 2004
1. Is it possible to setup at SqlDataAdapter to only .Fill() a DataTable
with the rows that have changed? ie, if I have a table with 10,000
records in it, and I change 1 of them, can .Fill() only change that 1
row (nice & quick), rather than re-populate all 10,00 rows (which would
take some time)

2. After loading a DataTable using SqlDataAdapter.Fill(), is it possible
to do this:
a) Save that table to Xml (Load it into a DataSet, then
DataSet.WriteXml()).
b) Load it back again (DataSet.ReadXml())
c) Use another SqlDataAdapter to .Fill() the table properly, knowing
that the rows that already exist in the DataTable came from the
database, and should be updated/deleted if the database has made such
changes to them.
Currently I can only seem to make the SqlDataAdapter.Fill() method add
all the rows again (eg. if the table has 5 rows, after loading from Xml
and .Fill()ing, it contains 10). It's as if the SqlDataAdapter doesn't
know which Xml row matches each row in the database.
 
Reply With Quote
 
 
 
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      16th Sep 2004
1. Not directly. You can, however, add a timestamp column to your database
and select only newer records using respective SQL statement.

2.
a) Sure. Don't forget to save schema (separately or within XML).
b) Absolutely. Don't forget to load schema prior to the data.
c) Yes if you have unique primary key in this DataSet/DataTable.
DataAdapter will update rows with matching primary keys.
Without primary key it has no way to determine if row is already in the
DataSet and would simply add it again.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
> Date: Thu, 16 Sep 2004 15:46:04 +0100
> From: Jon Brunson <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk>
> User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502)
> X-Accept-Language: en-us, en
> MIME-Version: 1.0
> Subject: 2 questions. Partial SqlDataAdapter.Fill() and ReadXml()
> Content-Type: text/plain; charset=us-ascii; format=flowed
> Content-Transfer-Encoding: 7bit
> Message-ID: <Owokwu$(E-Mail Removed)>
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> NNTP-Posting-Host: public2-cosh5-6-cust58370.cosh.broadband.ntl.com

80.4.142.2
> Lines: 1
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
> Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.compactframework:61348
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> 1. Is it possible to setup at SqlDataAdapter to only .Fill() a DataTable
> with the rows that have changed? ie, if I have a table with 10,000
> records in it, and I change 1 of them, can .Fill() only change that 1
> row (nice & quick), rather than re-populate all 10,00 rows (which would
> take some time)
>
> 2. After loading a DataTable using SqlDataAdapter.Fill(), is it possible
> to do this:
> a) Save that table to Xml (Load it into a DataSet, then
> DataSet.WriteXml()).
> b) Load it back again (DataSet.ReadXml())
> c) Use another SqlDataAdapter to .Fill() the table properly, knowing
> that the rows that already exist in the DataTable came from the
> database, and should be updated/deleted if the database has made such
> changes to them.
> Currently I can only seem to make the SqlDataAdapter.Fill() method add
> all the rows again (eg. if the table has 5 rows, after loading from Xml
> and .Fill()ing, it contains 10). It's as if the SqlDataAdapter doesn't
> know which Xml row matches each row in the database.
>


 
Reply With Quote
 
Jon Brunson
Guest
Posts: n/a
 
      17th Sep 2004
Thanks for the reply.

Regarding #2, is this the correct code to save to Xml with the key info?


Dim dc As New SqlCommand("SELECT * FROM SomeTable", MyConnection)

dc.CommandType = CommandType.Text

Dim da As New SqlDataAdapter(dc)

da.MissingSchemaAction = MissingSchemaAction.AddWithKey

Dim ds as New DataSet

da.Fill(ds)

ds.WriteXmlSchema("data.xsd")

ds.WriteXml("data.xml")



Ilya Tumanov [MS] wrote:

> 1. Not directly. You can, however, add a timestamp column to your database
> and select only newer records using respective SQL statement.
>
> 2.
> a) Sure. Don't forget to save schema (separately or within XML).
> b) Absolutely. Don't forget to load schema prior to the data.
> c) Yes if you have unique primary key in this DataSet/DataTable.
> DataAdapter will update rows with matching primary keys.
> Without primary key it has no way to determine if row is already in the
> DataSet and would simply add it again.
>
> Best regards,
>
> Ilya
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> --------------------
>
>>Date: Thu, 16 Sep 2004 15:46:04 +0100
>>From: Jon Brunson <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk>
>>User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502)
>>X-Accept-Language: en-us, en
>>MIME-Version: 1.0
>>Subject: 2 questions. Partial SqlDataAdapter.Fill() and ReadXml()
>>Content-Type: text/plain; charset=us-ascii; format=flowed
>>Content-Transfer-Encoding: 7bit
>>Message-ID: <Owokwu$(E-Mail Removed)>
>>Newsgroups: microsoft.public.dotnet.framework.compactframework
>>NNTP-Posting-Host: public2-cosh5-6-cust58370.cosh.broadband.ntl.com

>
> 80.4.142.2
>
>>Lines: 1
>>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
>>Xref: cpmsftngxa06.phx.gbl

>
> microsoft.public.dotnet.framework.compactframework:61348
>
>>X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>>
>>1. Is it possible to setup at SqlDataAdapter to only .Fill() a DataTable
>>with the rows that have changed? ie, if I have a table with 10,000
>>records in it, and I change 1 of them, can .Fill() only change that 1
>>row (nice & quick), rather than re-populate all 10,00 rows (which would
>>take some time)
>>
>>2. After loading a DataTable using SqlDataAdapter.Fill(), is it possible
>>to do this:
>> a) Save that table to Xml (Load it into a DataSet, then
>>DataSet.WriteXml()).
>> b) Load it back again (DataSet.ReadXml())
>> c) Use another SqlDataAdapter to .Fill() the table properly, knowing
>>that the rows that already exist in the DataTable came from the
>>database, and should be updated/deleted if the database has made such
>>changes to them.
>>Currently I can only seem to make the SqlDataAdapter.Fill() method add
>>all the rows again (eg. if the table has 5 rows, after loading from Xml
>>and .Fill()ing, it contains 10). It's as if the SqlDataAdapter doesn't
>>know which Xml row matches each row in the database.
>>

>
>

 
Reply With Quote
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      17th Sep 2004
Yes, that should do it. DataSet structure description including key(s) will
be saved to schema file.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
> Date: Fri, 17 Sep 2004 09:39:43 +0100
> From: Jon Brunson <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk>
> User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502)
> X-Accept-Language: en-us, en
> MIME-Version: 1.0
> Subject: Re: 2 questions. Partial SqlDataAdapter.Fill() and ReadXml()
> References: <Owokwu$(E-Mail Removed)>

<(E-Mail Removed)>
> In-Reply-To: <(E-Mail Removed)>
> Content-Type: text/plain; charset=us-ascii; format=flowed
> Content-Transfer-Encoding: 7bit
> Message-ID: <##(E-Mail Removed)>
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> NNTP-Posting-Host: public2-cosh5-6-cust58370.cosh.broadband.ntl.com

80.4.142.2
> Lines: 1
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
> Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.compactframework:61416
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> Thanks for the reply.
>
> Regarding #2, is this the correct code to save to Xml with the key info?
>
>
> Dim dc As New SqlCommand("SELECT * FROM SomeTable", MyConnection)
>
> dc.CommandType = CommandType.Text
>
> Dim da As New SqlDataAdapter(dc)
>
> da.MissingSchemaAction = MissingSchemaAction.AddWithKey
>
> Dim ds as New DataSet
>
> da.Fill(ds)
>
> ds.WriteXmlSchema("data.xsd")
>
> ds.WriteXml("data.xml")
>
>
>
> Ilya Tumanov [MS] wrote:
>
> > 1. Not directly. You can, however, add a timestamp column to your

database
> > and select only newer records using respective SQL statement.
> >
> > 2.
> > a) Sure. Don't forget to save schema (separately or within XML).
> > b) Absolutely. Don't forget to load schema prior to the data.
> > c) Yes if you have unique primary key in this DataSet/DataTable.
> > DataAdapter will update rows with matching primary keys.
> > Without primary key it has no way to determine if row is already in the
> > DataSet and would simply add it again.
> >
> > Best regards,
> >
> > Ilya
> >
> > This posting is provided "AS IS" with no warranties, and confers no

rights.
> >
> > --------------------
> >
> >>Date: Thu, 16 Sep 2004 15:46:04 +0100
> >>From: Jon Brunson <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk>
> >>User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502)
> >>X-Accept-Language: en-us, en
> >>MIME-Version: 1.0
> >>Subject: 2 questions. Partial SqlDataAdapter.Fill() and ReadXml()
> >>Content-Type: text/plain; charset=us-ascii; format=flowed
> >>Content-Transfer-Encoding: 7bit
> >>Message-ID: <Owokwu$(E-Mail Removed)>
> >>Newsgroups: microsoft.public.dotnet.framework.compactframework
> >>NNTP-Posting-Host: public2-cosh5-6-cust58370.cosh.broadband.ntl.com

> >
> > 80.4.142.2
> >
> >>Lines: 1
> >>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
> >>Xref: cpmsftngxa06.phx.gbl

> >
> > microsoft.public.dotnet.framework.compactframework:61348
> >
> >>X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
> >>
> >>1. Is it possible to setup at SqlDataAdapter to only .Fill() a

DataTable
> >>with the rows that have changed? ie, if I have a table with 10,000
> >>records in it, and I change 1 of them, can .Fill() only change that 1
> >>row (nice & quick), rather than re-populate all 10,00 rows (which would
> >>take some time)
> >>
> >>2. After loading a DataTable using SqlDataAdapter.Fill(), is it

possible
> >>to do this:
> >> a) Save that table to Xml (Load it into a DataSet, then
> >>DataSet.WriteXml()).
> >> b) Load it back again (DataSet.ReadXml())
> >> c) Use another SqlDataAdapter to .Fill() the table properly, knowing
> >>that the rows that already exist in the DataTable came from the
> >>database, and should be updated/deleted if the database has made such
> >>changes to them.
> >>Currently I can only seem to make the SqlDataAdapter.Fill() method add
> >>all the rows again (eg. if the table has 5 rows, after loading from Xml
> >>and .Fill()ing, it contains 10). It's as if the SqlDataAdapter doesn't
> >>know which Xml row matches each row in the database.
> >>

> >
> >

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sqldataadapter fill slow incolsa@leveltelecom.es Microsoft Dot NET 1 26th Jun 2006 01:31 PM
SqlDataAdapter.Fill problems Seiche V via DotNetMonster.com Microsoft C# .NET 0 14th Jun 2005 05:00 PM
TimeOut on SqlDataAdapter.Fill Dan Microsoft ASP .NET 1 3rd Apr 2004 12:05 AM
How does SqlDataAdapter.Fill work? Matthew Vandergrift Microsoft ADO .NET 2 17th Nov 2003 03:14 AM
SqlDataAdapter.Fill Jerry S Microsoft C# .NET 1 10th Oct 2003 09:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.