开发者

Check Constraints on DataRow Add

    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["Value开发者_JS百科One"] = "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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜