InvalidCastException in dataset designer generated code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dalberg

    InvalidCastException in dataset designer generated code

    The code below (generated by the dataset designer) is receiving an
    exception because the 'searchfor' column has nulls but this column in SQL
    Server allows nulls. What am I missing? Shouldn't the generated code check
    for DBNull first?





    [System.Diagnost ics.DebuggerNon UserCodeAttribu te()]
    public string SearchFor {
    get {
    try {
    return
    ((string)(this[this.tableXML.S earchForColumn])); }
    catch (System.Invalid CastException e) {
    throw new System.Data.Str ongTypingExcept ion("The
    value for column \'SearchFor\' in table
    \'XMLElement\' is DBNull.", e); }
    }
    set {
    this[this.tableXML.S earchForColumn] = value;
    }
    }

    John Dalberg
Working...