如何在数据表 c#asp.net 中一起检查第一、第二和第三行?

我有一个这样的表结构(如图所示),如果第一行应该是 (authlevel=1,authorized=1) AND 第 2 行(authlevel=2 和authorized=0 或 null)AND 第 3 行,我想要这样的条件(authlevel=3 and (authorized=0 or null)) AND





我已经尝试了下面的代码,但无法理解。


    Dictionary<string, BO.User> lstuserCH = new Dictionary<string, BO.User>();

            foreach (DataRow row1 in _data.wsm_PurchaseOrder_Auth) {

                if (((Convert.ToInt32(row1("AuthLevel")) == 1) 

                            && !row1.IsNull("Authorised"))) {

                    // here i need only the 1st element of dictonary lstuserCH


                }

      else

       {

      //dictionary lstuserCH should be remain as it is.

       }

}

http://img1.mukewang.com/60badcef000184bd06340113.jpg

繁花不似锦
浏览 118回答 2
2回答

慕莱坞森

您可以选择单个行并执行如下业务逻辑:&nbsp; &nbsp; public void ValidateFirstThreeRows(DataTable dt)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (dt.Rows.Count < 3)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Handle this case&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; var row1 = dt.Rows[0];&nbsp; &nbsp; &nbsp; &nbsp; var row2 = dt.Rows[1];&nbsp; &nbsp; &nbsp; &nbsp; var row3 = dt.Rows[2];&nbsp; &nbsp; &nbsp; &nbsp; if ((int)row1["AuthLevel"] == 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && bool.TryParse(row1["Authorized"]?.ToString(), out bool result)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && (int)row2["AuthLevel"] == 2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && bool.TryParse(row2["Authorized"]?.ToString(), out result)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && (int)row3["AuthLevel"] == 3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && bool.TryParse(row3["Authorized"]?.ToString(), out result))&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Do your stuff&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP