Can't save renamed DataColumn

N

nvx

Hello.
I experience a problem with columns in a DataSet. I need to add,
remove, and rename columns in one table. I'd like to avoid changing
the columns, but unfortunately I can't.

The table is bound to a DataGridView. Adding and removing columns is
not a problem, this works perfectly. The problem is what to do when I
need to rename a column. I tried to rename the column in the DataTable
and change the DataPropertyName property of the corresponding
DataGridViewColumn. Everything seems to work fine. Then I want to save
the DataSet to a .mdb file, so I do the following:

1. remove the column that was renamed,
2. add a new one with the correct name,
3. mark all unchanged rows in the DataTable as modified,
4. rebuild the insert, delete, and update commands using the
CommandBuilder, and
5. call TableAdapter.Update(...);

This routine works perfectly if I add some new columns and/or remove a
few of them only. If I try to use this with a renamed column that was
already present in the DataSet, it fails. Although it does not throw
an exception, the saved file contains blank fields instead of the
values in the renamed column.

It confuses me a lot. What should I do to make this work?

Any help would be much appreciated.

Best regards,
nvx
 
W

W.G. Ryan

nvx:

I don't have an answer as to why it doesn't thrown an exception but what you
are trying to do is definitely doable - I just don't think it's doable with
CommadnBuilders. If you use a DataAdapter, you can just set the column
mappings so that whatever the parameter is for the column is taken from the
newly named column. CommandBuilders have rather limited functionality in
many respects and moreso when it comes to concurrency issues, so off the top
of my head, I wouldn't expect it to work here. there may be a way though and
that's what you're asking - let me try to recreate the problem and see if I
can come up with something. I can however promise you that if you use an
Adapter instead of a commandbuilder - you won't live to regret the change.
 

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

Top