Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Value between two column from datatable

Tags:

c#

asp.net

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

like image 312
Imran Azam Avatar asked May 26 '26 16:05

Imran Azam


1 Answers

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

like image 133
Ajay Avatar answered May 28 '26 05:05

Ajay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!