Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2006, 09:47 AM
Authorized User
 
Join Date: Jan 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in loaddatarow

i am facing a problem while updating a particular row in datatable by using loaddatarow.

i am giving the structure of the datatable

      DataTable temp= new DataTable();
      DataColumn pkCol = temp.Columns.Add("PCOD", typeof(String));
      temp.Columns.Add("PDES", typeof(String));
      temp.PrimaryKey = new DataColumn[] {pkCol};
      for( int i=0;i<5;i++)
       {
        DataRow myrow;
    myrow = temp.NewRow();
    myrow["PCOD"] = i
    myrow["PDES"] = "";
    temp.Rows.Add(myrow);
//now i am updating this datatable with loaddatarow for a test
        object[] newRow = new object[2];
        newRow[0] = i;
        newRow[1] = "abcgd"
        DataRow myRow;
        temp.BeginLoadData();
        myRow = temp.LoadDataRow(newRow, false);
        temp.EndLoadData();

       }

it is giving me an error on the line "temp.endloaddata",
"Unable to enable the constraint"
the only constraint here is primary key. i am unable to figure out why the method is unable to update the row.
any pointers to this will be of great help.

Note:--i tried even changing the 2nd parameter to "true " but of no use


regards
rahul pokharna
__________________
regards
rahul pokharna
 
Old June 18th, 2008, 07:56 PM
fig fig is offline
Registered User
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A new row is created and each column in the new row is filled with "System.Data.Row" for each row in the array your adding to the table.

I believe this is a bug. I have not found a way to fix it, if you add more rows in the array than you have columns in the table.

Debug the "enddataload" line and look at your table. You will see the error row at the bottom of the table. So, if you try to call this more than once and you have a unique column, you get your error above.



 
Old June 18th, 2008, 08:34 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It's interesting that it says it can't *ENABLE* the constraint.

Do you suppose that's only because the type of the column is string but the data you are trying to use is an integer???

Did you try simply changing
   DataColumn pkCol = temp.Columns.Add("PCOD", typeof(String));
to
   DataColumn pkCol = temp.Columns.Add("PCOD", typeof(Integer));
???

Or try using a string for the column value instead of just an int??
 
Old June 18th, 2008, 08:40 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

SHAME ON ME!!!

Sheesh, I made the foolish mistake of replying to a post made more than TWO YEARS AGO just because somebody else had (also foolishly) replied!

Sorry, folks!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
LoadDataRow causes DataRowState.Modified immediate rsnell ADO.NET 0 September 26th, 2004 11:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.