I have a datatable. I need to fetch a certain column value based on the user input. For example, lets say the datatable has three column intpkdata,intFrom,intTo Here is my some code,
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["intpkdata"] = new Random().Next(0, 99999).ToString();
drCurrentRow["intFrom"] = txtFrom.Text;
drCurrentRow["intTo"] = txtTo.Text;
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["Pcidata"] = dtCurrentTable;
gdvpciData.DataSource = dtCurrentTable;
gdvpciData.DataBind();
Requirement :
if intFrom/intTo data is already exist in datatable then msg should come.Pleas see the image for records
enter image description here
try this
string fromValue = "some value";
string toValue = "some value";
if(dtCurrentTable.AsEnumerable().Any(row => fromValue == row.Field<string>("intFrom") && toValue == row.Field<string>("intTo")))
{
//exists
}
see this ques. Check if value exists in dataTable?
Check if String / Record exists in DataTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With