I have a dataset in c# visual studio. I have one of column values of the one of the rows. I need to select that row using that value and store it in a datarow so that I can delete it. So how can I get the row of the datatable from one of the column values. I was trying something like this:
DataRow rowtobeselected = TableName["SerialNumber = 156"];
But as you know this is wrong. Also I need to get another colum value from this row. For eg I need to get the value from the column date.
string Date = rowtobeselected.date;
I want to do something like this. So how to do it correctly. Thank you.
DataTables support a SQL like Select syntax:
https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.select?view=net-5.0
DataRowView row = (DataRowView)OtherTable.SelectedItem;
string serialnumbr = row.Row["SerialNumber"].ToString();
DataRow[] result = TableName.Select("SerialNumber =" + serialNumbr);
DataRow dr = result.FirstOrDefault();
if (dr != null)
{
DateTime dt = DateTime.Parse(dr["Date"].ToString());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.