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.
精彩评论