Thanks for your reply. However, when I set acceptchangesduringfill = false I
"ClientTable". which has to happen in my case. Oh well, I guess these are
"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:O3oZJAGnGHA.4604@TK2MSFTNGP02.phx.gbl...
> Bryan,
>
> This is not so clean but probably will it work (I never did this but you
> can try)
>
> I assume that your clienttable has everywhere the rowstate added
>
>
http://msdn2.microsoft.com/en-us/library/system.data.datarowstate.aspx >
> If not than you have to retrieve (fill) this datatable with
>
> Acceptchangesduringfill = false
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondataadapterclassacceptchangesduringfilltopic.asp
>
> You do first an insert from your clienttable on the database server from
> all rows.
> (you have to make your own insertcommand for that.
> (I assume that the schemas are the same)
> Than you set on the dataadapter during that update (insert)
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondataadapterclasscontinueupdateonerrortopic.asp
>
> Than you can update all rows with an error which says it exist already,
> however you put in the insert command of the dataadapter an update SQL
> String.
>
http://msdn2.microsoft.com/en-us/library/system.data.datarow.rowerror.aspx >
> (You have to copy these rows to a seperate datatable using a for each and
> be aware to keep the rowstate the same.)
>
> The problem is that you cannot affect the update rowstate, otherwise you
> could have used the update part of the dataadapter instead what I write
> now the insertpart.
>
> I would not know why this would not work, however as I said, I have never
> tried this, and therefore you have to try it yourself. If this works, than
> please reply.
>
> Cor
>
>
>
>
> "Bryan" <BryanZM@nospam.nospam> schreef in bericht
> news:OzCqAnFnGHA.4164@TK2MSFTNGP05.phx.gbl...
>> Ok, let me make this more clear. Is there any way to make what I have
>> shown quicker rather than so slow????
>>
>> The server datatable comes from a call to a remote server, then I read
>> through that datatable and see if there are any hits on the client
>> datatable, if so I do an update, if not I do an add.
>>
>> Surely there must be something faster than the approach I am using?
>>
>>
>> "Bryan" <BryanZM@nospam.nospam> wrote in message
>> news:%23ZC5w08mGHA.1272@TK2MSFTNGP02.phx.gbl...
>>> Hello,
>>> I am trying to speed up the process for updating a datatable with new
>>> rows.
>>>
>>> First of all I have 2 datatables, ServerTable and ClientTable,
>>> ServerTable is from a remote datasource, it has new, and updated records
>>> in it. ClientTable exists on the client. It needs the new/updated
>>> records from the ServerTable. So I have created a loop that loops
>>> through all the records in the ServerTable and for each record checks
>>> the primary key of the ClientTable to and gets a like DataRow below:
>>>
>>> object[] key =
>>> {drServer["UPC"].ToString(),drServer["ItemNum"].ToString()} ;
>>>
>>> DataRow drClient =
>>> DataClass.dsGrids.Tables["ClientTable"].Rows.Find(key) ;
>>>
>>> if it finds a datarow then it will change certain fields in drClient
>>> like this:
>>>
>>> drClient["field1"] = drServer["field1"] ;
>>>
>>> drClient["field2"] = drServer["field2"] ;
>>>
>>> if there is no match because drClient is null then I do an
>>> Row.Add(drServer) on the ClientTable.
>>>
>>> This is where it slows down considerably. It seems to take more than 3
>>> minutes to add only 15,000 records to the ClientTable, then after the
>>> loop I apply the update to the database (I am even using the new 2.0
>>> batch update) takes another 3 or more minutes for this to occur,
>>> although it does seem when I change it to the batchupdate it ran a
>>> little quicker. Please see the full example code below:
>>>
>>> foreach(DataRow drServer in dtServer.Rows) // iterrate through the new
>>> records, loop take more than 3 minutes for 15,000+ records
>>> {
>>> object[] key =
>>> {drServer["UPC"].ToString(),drServer["ItemNum"].ToString()} ;
>>>
>>>
>>>
>>> DataRow drClient =
>>> DataClass.dsGrids.Tables["ClientTable"].Rows.Find(key) ;
>>>
>>>
>>>
>>>
>>> if(drClient != null) //Update row
>>> {
>>> drClient["field1"] = drServer["field1"] ;
>>> drClient["field2"] = drServer["field2"] ;
>>> ... 20+ more fields to update...
>>>
>>>
>>> }
>>> else //Add row
>>> {
>>> drClient = DataClass.dsGrids.Tables["ClientTable"].NewRow() ;
>>> drClient["field1"] = drServer["field1"] ;
>>> drClient["field2"] = drServer["field2"] ;
>>> ... 44 more fields to add...
>>>
>>> DataClass.dsGrids.Tables["ClientTable"].Rows.Add(drN) ;
>>> }
>>>
>>>
>>>
>>> }
>>>
>>>
>>> DataClass.daClientTable.UpdateCommand.UpdatedRowSource =
>>> UpdateRowSource.None;
>>> DataClass.daClientTable.InsertCommand.UpdatedRowSource =
>>> UpdateRowSource.None;
>>>
>>> DataClass.daClientTable.UpdateBatchSize = 20;
>>>
>>> int Update =
>>> DataClass.daAllSigns.Update(DataClass.dsGrids.Tables["ClientTable"]) ;
>>> // Update take more than 3 minutes for Update
>>>
>>>
>>>
>>> Anyone know what I am doing wrong? Surely it can be quicker....?
>>>
>>> Any help would be great!
>>>
>>> Thanks, Bryan
>>>
>>>
>>>
>>>
>>
>>
>
>