Truly frustrated

  • Thread starter Thread starter cjobes
  • Start date Start date
C

cjobes

Hi all,

I don't know how many hours I've spend on this but I don't want to give up
and there has to be a way of doing this. Here is what I'm trying to do:

I have a small Windows Forms app where I create a DataSet to hold temp info.
I do not need to display the data to the user but I need to manipulate the
data with code. There is just one table in the set with 8 columns. One of
the columns is configured as a PK. In the code I step through the rows and
test for conditions. Once I have found a row that meets the condition I need
to update one column of the row with new data.

The books (I have several that I bought out of desperation looking for
answers) say that if you have a unique key (PK is def. unique) and you use
the dt.rows.add with an existing value for the PK, it will replace data
rather than creating a new row. When I tried that an exception was thrown. I
then used the dt.BeginLoadData. That didn't work either. It still created a
new row and when I issued the dt.EndLoadData I got an exception that there
are 2 rows with the same value.

Can anybody tell me how I can change the value of one column through code
without binding den DataSet to a list or DataGrid? There has to be a way of
doing this.

Thanks
Claus
 
I did find it. For anybody that runs into the same issue it's soooooooo
simple once you figure it out but it is not documented anywhere. The key is
ds.AcceptChanges.
I created an incident of the row, replace the one value and then issued a
ds.AcceptChanges.
 
Cjobes,

It can be the solution, know however that "acceptchanges" set all datarows
too "unchanged" and therefore makes it impossible to update those too a
database after that.

Maybe this helps?

Cor
 
Thanks Cor,

In this case there is no database. What I use this for is to read a
delimeted txt file, manipulate the text and write it back to another file.
But for future reference, what other option would I have?

Claus
 
Cjobes

The books (I have several that I bought out of desperation looking for
answers) say that if you have a unique key (PK is def. unique) and you use
the dt.rows.add with an existing value for the PK, it will replace data
rather than creating a new row.

Weird book, I never have noticed that.

And should have been written here when it was like that in my opinion.
http://msdn.microsoft.com/library/d...fSystemDataDataRowCollectionClassAddTopic.asp

And it is n my opinion absolute not logical.

A datarow is an object that holds only references to items which are objects
again. Would be a kind of those strange methods we saw in past in VB6, which
some people like, however not me.

For me it is in that standalone dataset just testing on existing key, as
that not exist create a new row with a new key and than replace the values
in that newrow or that existing row. (not in the key).

When it is about a form you can look by the way as well to the databinding,
than you can use the currencymanager.addnew.

I hope this helps?

Cor


">
 
doh,
That part is not from me, before somebody misunderstand this.

Cor
 
Cor

Thanks for your help. Here is the book:
Francesco Balena "Programming Microsoft Visual Basic.Net Page 1064 (mid
page).

Claus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top