这是一个独立的问题,与我之前在SO上提出的问题相矛盾。
我在gist.github发布了我的完整来源的副本,我只有一个我无法解决的问题。
FindLine()
始终返回-1。我已经确认这两个变量正在传递好的数据,所以我无法弄清楚为什么比较永远不会返回-1以外的任何变量。
如果您不想查看完整的来源,请参阅以下相关代码片段:
DataTable resultTable = new DataTable();
string ImportPath = @"***PATH***\***INFILE***.csv";
string QueryString = "SELECT DISTINCT UPPER(MP.Symbol) AS Symbol, LOWER(MP.SecType) AS SecType, MBI.Status FROM MoxySecMaster AS MP LEFT JOIN MoxyBondInfo AS MBI ON MP.Symbol = MBI.Symbol AND MP.SecType = MBI.SecType WHERE MP.SecType <> 'caus' AND MP.SecType IS NOT NULL AND MP.Symbol IS NOT NULL ORDER BY Symbol ASC;";
string symb = "";
StringBuilder OrigText = new StringBuilder();
SqlConnection MoxyConn = new SqlConnection("server=***;database=***;user id=***;password=***");
SqlDataAdapter adapter = new SqlDataAdapter(QueryString, MoxyConn);
MoxyConn.Open();
resultTable = new DataTable();
adapter.Fill(resultTable);
MoxyConn.Close();
OrigText.Append(File.ReadAllText(ImportPath));
char[] tempSymb = new char[10];
OrigText.CopyTo(0, tempSymb, 0, OrigText.ToString().IndexOf(",", 0));
symb = new string(tempSymb);
int foundSpot = FindLine(symb, resultTable);
......和......
static int FindLine(string symbol, DataTable symbolList)
{
for (int vcl = 0; vcl < symbolList.Rows.Count; vcl++)
{
if (symbolList.Rows[vcl][0].ToString() == symbol.ToUpper())
return vcl;
}
return -1;
}
答案 0 :(得分:4)
尝试使用:
if (String.Equals(symbolList.Rows[vcl][0].ToString().Trim(),
symbol, StringComparison.InvariantCultureIgnoreCase))