在 asp.net 中循环遍历数组不起作用

他们

我有一个数组,它有时会保存类似的值"ABC, XYZ, TTT",有时只保存这样的值"ABC"。因此,当它保存多个数组时,它只检查第一项而不是其他项。

string[] strStateArray = new string[] { "" };
                    strStateArray = strOne.Split(',');

 for (int i = 0; i < strStateArray.Length; i++)
                    {                            
                        if (dt.Rows[0]["CIRCLE"].ToString() == strStateArray[i].ToString()) // not checking for multiple items
                        {
            }
        }

更新代码

for (int i = 0; i < strStateArray.Length; i++)
                    {
                        if (dt.Rows[0]["CIRCLE"].ToString() == strStateArray[i].Trim().ToString())
                        {
                            if (dt.Rows.Count > 0)
                            {
                                dt.TableName = "RecodSet";
                                string xml = ConvertDatatableToXML(dt);
                                mycon.Close();

                                ScriptManager.RegisterStartupScript(this, this.GetType(), key, "alert('File uploaded successfully.!!');", true);
                                //  System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('File uploaded successfully.!!');", true);
                            }
                            else
                            {
                                string noData = "No data to upload.";
                                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", noData, false);

                            }
                        }
                        else
                        {
                            string file_name = fluUploadBtn.FileName;

                            if ((System.IO.File.Exists(file_name)))
                            {
                                System.IO.File.Delete(file_name);
                            }
                            ScriptManager.RegisterStartupScript(this, this.GetType(), key, "alert('User is not authorised to upload data for state mentioned in excel report ');", true);
                        }                            
                    }
用户3682728

那你能去调试一下这个值吗?

让我为你重写一些代码

String logMsg ="";
String targetKeyword = dt.Rows[0]["CIRCLE"].ToString();
for (int i = 0; i < strStateArray.Length; i++)
{
       String tmp_Val_Pure = strStateArray[i] ==null? null : strStateArray[i].ToString();   //debug here see the value1
       String tmp_Val = strStateArray[i] ==null? "" : strStateArray[i].ToString().Trim(); //debug here see the value2
       bool isThisOk =  (targetKeyword == tmp_Val );   //debug here see the val of isThisOk 
      if ( isThisOk  )
      {
          logMsg += "Success Record : "+ i.ToString() + " val : " + tmp_Val ; 
           if (dt.Rows.Count > 0)
            {  // alert case OK
            } else { // alert no val dt  }
      }
      else
      {  
          logMsg += "Err Record : "+ i.ToString() + " val : " + tmp_Val ;           
      }
} //end loop
//Go check logMsg

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章