我有一個陣列,它有時會保存類似的值"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);
}
}
uj5u.com熱心網友回復:
那你能去除錯一下這個值嗎?
讓我為你重寫一些代碼
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490686.html
