none
typed datasets and Add...Row with optional values? RRS feed

  • Question

  • Hi!

    I've got a typed Dataset with a table than contains a key and one additional column (UInt16) where AllowDbNull is set to true.

    So, when I call

    DSet.AddMyTableRow(string Key, UInt16 Value)

    how do I leave out the Value? Shouldn't the method look like

    DSet.AddMyTableRow(string Key, UInt16? Value)

    or so?

     

    Lots of Greetings!

    Volker

     

     


    Volker
    • Moved by SamAgain Friday, June 18, 2010 2:43 AM better fit (From:.NET Base Class Library)
    Thursday, June 17, 2010 1:25 PM

Answers

  • Try adding it like this and then set the columns that are not DBNull.Value:

    // Assuming your DataSet class is called MyDataSet
    // I'm also making assumptions as to the column names
    MyDataSet.MsgKeyWordRow row = (MyDataSet.MsgKeyWordRow)DSet.MsgKeyWord.NewRow();
    
    row["message"] = parentMessageRowByFK_Message_MsgKeyWord;
    row["keyword"] = parentKeyWordRowByFK_KeyWord_MsgKeyWord;
    // note that I did not set the column that contains DBNull.Value
    // because that will be what it defaults to
    
    // then add the new row
    DSet.MsgKeyWord.AddMsgKeyWordRow(row);
    

    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Proposed as answer by liurong luo Monday, June 21, 2010 10:56 AM
    • Marked as answer by Hetzi Monday, June 21, 2010 2:49 PM
    Saturday, June 19, 2010 8:20 PM

All replies

  • Hi,

    the answer is

    DSet.AddMyTableRow(string Key, DBNull.Value);

    Regards

    Thursday, June 17, 2010 9:18 PM
  • Argument 3: Cannot convert from System.DbNull to ushort.

    AddMsgKeyWordRow(parentMessageRowByFK_Message_MsgKeyWord, parentKeyWordRowByFK_KeyWord_MsgKeyWord,DBNull.Value);


    Volker
    Friday, June 18, 2010 12:42 PM
  • Try adding it like this and then set the columns that are not DBNull.Value:

    // Assuming your DataSet class is called MyDataSet
    // I'm also making assumptions as to the column names
    MyDataSet.MsgKeyWordRow row = (MyDataSet.MsgKeyWordRow)DSet.MsgKeyWord.NewRow();
    
    row["message"] = parentMessageRowByFK_Message_MsgKeyWord;
    row["keyword"] = parentKeyWordRowByFK_KeyWord_MsgKeyWord;
    // note that I did not set the column that contains DBNull.Value
    // because that will be what it defaults to
    
    // then add the new row
    DSet.MsgKeyWord.AddMsgKeyWordRow(row);
    

    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Proposed as answer by liurong luo Monday, June 21, 2010 10:56 AM
    • Marked as answer by Hetzi Monday, June 21, 2010 2:49 PM
    Saturday, June 19, 2010 8:20 PM
  • So there is no better way. Thanks a lot!

    Volker


    Volker
    Monday, June 21, 2010 2:49 PM
  • You're welcome ... and it's actually easier/cleaner than supplying all the parameters in one Add method. At least in my opinion. ;0)
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, June 23, 2010 11:05 PM