I have a connection to an Excel document and I want to pull rows where columnX > @param1. The column in question contains a Double value (1.01) and @param1 is a double as well (1.1). This row should not meet the criteria, yet while debugging I see the datareader has rows and proceeds down if statements using that row info.
Code:
double ppugt = 1.1;
cmd.CommandText = "select columnX from [Voltage$] where (((Area like '%EDE%') or (Area like '%ede%')) and (columnX > @param1))";
cmd.Parameters.AddWithValue("param1", ppugt);
dataReader = cmd.ExecuteReader();
if (dataReader.HasRows)
{
while (dataReader.Read())
{
double ubparam = Convert.ToDouble(cmd.Parameters[2].Value.ToString());
double postpu = Convert.ToDouble(dataReader[0].ToString());
if (ubparam > postpu)
{
string mytest = "";
}
The command has some other parameters so Parameters[2] is the correct entry that holds the value for ubparam. The last if block is the code that contradicts the returned row. The SELECT statement pulls rows where the value is greater than the parameter, yet the code executes the if statement as if the parameter is greater than the column value (which it is)
Aucun commentaire:
Enregistrer un commentaire