Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

ColumnMappings don't seem to work!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Juan Dent - 24 May 2005 00:42 GMT
Hi,

I am new to column mappings and can't seem to make them work. The following
is an example:

    DataTable table = new DataTable( "SYSTEM.Usernames");
    table.Columns.Add( "S1", typeof(decimal) );
    OracleCommand cmd = new OracleCommand();
    cmd.Connection = this.oracleConnection1;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT SuperUserFlag FROM SYSTEM.Usernames WHERE
Username = 'JuanDent'";
    OracleDataAdapter da = new OracleDataAdapter( cmd );
    DataSet ds = new DataSet( "Temp ds");
    ds.Tables.Add( table );

    DataTableMapping map = da.TableMappings.Add( "Table", table.TableName );
    map.ColumnMappings.Add( "S1", "SuperUserFlag" );

               ds.EnforceConstraints = false;
    da.MissingSchemaAction = MissingSchemaAction.Error;
    try
    {
            da.Fill( ds, 0, 200, table.TableName );
    }
    catch( Exception ex )
    {
             MessageBox.Show( ex.Message, ex.Source);
    }

No matter how I play with it, I can't get the Fill statement to work, it
always asks for a missing column "SuperUserFlag" in the table - I thought
this is precisely what column mappings did for us...

Signature

Thanks in advance,

Juan Dent, M.Sc.

Kevin Yu [MSFT] - 24 May 2005 03:42 GMT
Hi Juan,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you can't get TableMappings to work in
your app. If there is any misunderstanding, please feel free to let me know.

Thanks for posting your code here. Based on the code you have provided, I
can see that the source table name is incorrect which make the Fill throws
exception. When filling, we have to fill to the source table and then
TableMappings will map it to the destination table.

Also the source column name and destination column name has to be swapped.

Here I made some changes to your code, and it works fine on my machine.

    DataTable table = new DataTable( "SYSTEM.Usernames");
    table.Columns.Add( "S1", typeof(decimal) );
    OracleCommand cmd = new OracleCommand();
    cmd.Connection = this.oracleConnection1;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT SuperUserFlag FROM SYSTEM.Usernames WHERE
Username = 'JuanDent'";
    OracleDataAdapter da = new OracleDataAdapter( cmd );
    DataSet ds = new DataSet( "Temp ds");
    ds.Tables.Add( table );

    DataTableMapping map = da.TableMappings.Add( "Table", table.TableName );
    map.ColumnMappings.Add( "SuperUserFlag", "S1" );

               ds.EnforceConstraints = false;
    da.MissingSchemaAction = MissingSchemaAction.Error;
    try
    {
            da.Fill( ds, 0, 200, "Table");
    }
    catch( Exception ex )
    {
             MessageBox.Show( ex.Message, ex.Source);
    }

HTH.

Kevin Yu
Signature

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

Juan Dent - 24 May 2005 17:40 GMT
Thanks. However, I have changed all you have suggested and I still get a
missing column with name "SuperUserFlag"...

I am puzzled...

What is the purpose of DataMapping then? is it incapable of mapping a column
with one name in the SELECT statement to a column with another name in the
DataTable given to the DataSet which is then given to the DataAdapter?

Signature

Thanks in advance,

Juan Dent, M.Sc.

> Hi Juan,
>
[quoted text clipped - 42 lines]
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
Kevin Yu [MSFT] - 25 May 2005 06:01 GMT
Hi Juan,

DataMapping is used to put the selected data to the desired column in your
DataSet. I tried this code snippet on my machine and it works fine.
map.ColumnMappings.Add( "SuperUserFlag", "S1" ); is used to map
SuperUserFlag column to S1. Could you please check it again?

Kevin Yu
Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.