views:

83

answers:

1
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("ValueOne",typeof(string)){AllowDBNull = false});
    dt.Columns.Add(new DataColumn("ValueTwo",typeof(string)){AllowDBNull = false});

    DataRow row = dt.NewRow();
    row["ValueOne"] = "Test1";
    if (dt.Rows.CanAdd(row))
    {
        dt.Rows.Add(row);
    }

Is there some way to Check if a Row Can be Added before trying to add the row?

+1  A: 

There is no way to automatically do this. What would you do instead? If you just want to skip the row you could put it into a try/catch but make sure you only catch the specific exception.

Ben Robinson