C#-检查字符串是否在数据行中
基本上我有一个数据表a(见-),其中包含日期及其对应的日期 我还有另一个DataTable B,其中包含零售商可以交货的天数列表(请参见-) 我想做的是循环遍历DataTable A中的每一行,如果日期在DataTable B中,则将其显示在屏幕上 到目前为止,我有这个,但现在我卡住了C#-检查字符串是否在数据行中,c#,datatable,datarow,C#,Datatable,Datarow,基本上我有一个数据表a(见-),其中包含日期及其对应的日期 我还有另一个DataTable B,其中包含零售商可以交货的天数列表(请参见-) 我想做的是循环遍历DataTable A中的每一行,如果日期在DataTable B中,则将其显示在屏幕上 到目前为止,我有这个,但现在我卡住了 // Firstly call the stored procedure to obtain the list available delivery dates (this is basically to
// Firstly call the stored procedure to obtain the list available delivery dates (this is basically today plus 14 days)
DataTable availableDatesRecord = new DataTable();
B2B.Data.CometB2BDB comet = new CometB2BDB();
StoredProcedure proc = comet.GetListOfAvailableDates(now);
DbDataReader reader = proc.ExecuteReader();
availableDatesRecord.Load(reader);
// Now we need to obtain the list of days we can deliver - this is all based on their postcode.
DataTable possibleDeliveryDayRecord = new DataTable();
proc = comet.GetDeliveryDatesByPostcode(postcode);
reader = proc.ExecuteReader();
possibleDeliveryDayRecord.Load(reader);
DataRow deliveryDays = possibleDeliveryDayRecord.Rows[1];
foreach (DataRow row in availableDatesRecord.Rows)
{
string deliveryDay = row["Day"].ToString();
}
最有效的方法是什么
Steven加入列表和数据表可能就是您想要的。你会用Linq吗?如果是这样,答案是肯定的 如果您仍然在2.0中,那么我只需要在datarows上执行嵌套循环,比如
List<string> days;
foreach(DataRow dr in table.Rows)
if days.Contains(dr[columnname])
Console.WriteLine(dr[columnname]);
列表天数;
foreach(table.Rows中的数据行dr)
if days.Contains(dr[columnname])
Console.WriteLine(dr[columnname]);
加入列表和数据表可能就是您想要的。你会用Linq吗?如果是这样,答案是肯定的
如果您仍然在2.0中,那么我只需要在datarows上执行嵌套循环,比如
List<string> days;
foreach(DataRow dr in table.Rows)
if days.Contains(dr[columnname])
Console.WriteLine(dr[columnname]);
列表天数;
foreach(table.Rows中的数据行dr)
if days.Contains(dr[columnname])
Console.WriteLine(dr[columnname]);
此简单方法提供了一些基本功能:
字符串[]天={“星期一”、“星期二”、“星期日”}
此简单方法提供了一些基本功能: 字符串[]天={“星期一”、“星期二”、“星期日”}
你已经试过什么了?你能发布你现有的代码吗?你的日期列表是什么类型的?字符串,枚举类型,…?您已经尝试了什么?你能发布你现有的代码吗?你的日期列表是什么类型的?字符串,枚举类型,。。。?