This is a separate problem lingering from a previous question I asked here on SO.
I've posted a copy of my full source at gist.github and I only have one lingering problem that I can't resolve.
FindLine()
always returns -1. I have confirmed that the two variables are getting passed good data, so I can't figure out why the comparisons never return anything other than -1.
Here's a snippet of the relevant code if you don't want to check out the full source:
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();
resultTab开发者_如何学JAVAle = 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);
... and ...
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;
}
try using this:
if (String.Equals(symbolList.Rows[vcl][0].ToString().Trim(),
symbol, StringComparison.InvariantCultureIgnoreCase))
精彩评论