Error when changing data value in strongly typed dataset table?

Discussion in 'ASP .Net' started by Keithb, Oct 25, 2006.

  1. Keithb

    Keithb Guest

    I am trying to change the value of a field in a table that is a member of
    strongly typed DataSet. The code:

    foreach (DataRow rw in dt.Rows) {
    rw.ItemArray[16] = (string)c3Text;
    }

    does not change the content of the item.

    Using debugging tools to look at rw, I see this message where the data
    should be.

    "c3LabelText = '((DataSet1.DisplayRow)(rw)).c3LabelText' threw an exception
    of type 'System.Data.StrongTypingException'"

    What am I doing wrong?

    Thanks,

    Keith
    Keithb, Oct 25, 2006
    #1
    1. Advertising

  2. Keithb

    LosManos Guest

    hejdig.
    >I am trying to change the value of a field in a table that is a member of
    >strongly typed DataSet. The code:
    > foreach (DataRow rw in dt.Rows) {
    > rw.ItemArray[16] = (string)c3Text;
    > }
    > does not change the content of the item.
    > Using debugging tools to look at rw, I see this message where the data
    > should be.
    > "c3LabelText = '((DataSet1.DisplayRow)(rw)).c3LabelText' threw an
    > exception of type 'System.Data.StrongTypingException'"


    If c3Text is a textbox (hard to tell from the variable name) then you
    probably want to use c3Text.Text since you otherwise try to cast a TextBox
    object to a System.String.

    Another possibility, though I doubt it, is that 16 is wrong. It is a large
    number and to count to the 17th item (which 16 points to) without jumping
    over a column might be tricky.
    Couldn't you use something like
    rw[ dt.myColumn.ColumnName ] = ....
    because then you know you are at the right place.
    ?

    HTH

    /OF
    LosManos, Oct 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Narayanan Sankaranarayanan

    Custom Namespace For Strongly Typed DataSet

    Narayanan Sankaranarayanan, Dec 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,070
    Narayanan Sankaranarayanan
    Dec 15, 2004
  2. Imran

    Strongly Typed dataset

    Imran, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    560
    Richard A. Lowe
    Jan 23, 2004
  3. =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?=

    Help with creating strongly typed DataSet

    =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    499
    Rick Strahl [MVP]
    Apr 19, 2004
  4. Spotnick
    Replies:
    0
    Views:
    1,554
    Spotnick
    Jan 21, 2006
  5. Alan Silver
    Replies:
    2
    Views:
    644
    Alan Silver
    Jul 20, 2006
Loading...

Share This Page