Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Id Value
- 1 football
- 2 Tennis
- 3 Cricket
- var dataTable = dataSet.Tables[0]; //For this example I'm just getting the first DataTable of the DataSet, but it could be other.
- var id = 1;
- var value = "football";
- //Any(...) will return true if any record matches the expression. In this case, the expression is if a Id Field of the row is equals to the provided id
- var contained = dataTable.AsEnumerable().Any(x =>x.Field<int>("Id") == id);
- if(!contained)
- {
- var row = dataTable.NewRow();
- row["Id"] = id;
- row["Value"] = value;
- dataTable.Rows.Add(row);
- }
- DataRow newrow = ds.Tables[0].NewRow(); //assuming ds is your dataset
- newrow["id"] = "your new id value";
- newrow["value"] = "your new value";
- ds.Tables[0].Rows.Add(newrow);
Add Comment
Please, Sign In to add comment