PC Review


Reply
Thread Tools Rate Thread

Can't save renamed DataColumn

 
 
nvx
Guest
Posts: n/a
 
      29th Jan 2008
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
 
Reply With Quote
 
 
 
 
W.G. Ryan
Guest
Posts: n/a
 
      31st Jan 2008
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.

--
bill.ryan | technology.evangelist | magenic.technologies
mvp - device application development
http://www.msmvps.com/WilliamRyan
http://www.magenic.com
"nvx" <(E-Mail Removed)> wrote in message
news:6737ae64-c825-47d3-99f0-(E-Mail Removed)...
> 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



 
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
DataColumn =?Utf-8?B?T3NjYXIgUGF0YXJyb3lvIFZlbGFzY28=?= Microsoft C# .NET 6 12th Apr 2006 03:51 AM
binding datacolumn to another datacolumn in a datagrid bpdace Microsoft C# .NET 0 23rd Nov 2005 03:59 PM
CacheManager Fails to Save DataColumn DataType Change SoYouKnowBrig Microsoft Dot NET 0 19th Oct 2005 05:39 PM
Require Workbook to be renamed in order to Save It Steve Klenner Microsoft Excel Programming 1 13th Jul 2005 08:45 AM
How to add a datacolumn which points to another datacolumn Programatix Microsoft ADO .NET 1 30th Jan 2005 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:26 AM.