请检查代码中间的注释,它显示问题出在哪里以及我如何尝试解决它......谢谢!
问题出在语句中:“while ((ObjReader.Read()) && (counter <= 5))”。我放了一个断点,但光标只是不想进入while循环!我试图在该语句的上方编写:“ObjReader.Read()”,它可以正常读取它,但它不想在 while 循环中读取它......
public static void Convert(OleDbConnection MyConn, double strike1_run, double time0_run)
{
string value1 = "";
string value2 = "";
string value3 = "";
string T0 = "";
string T1 = "";
string VolT0K1 = "";
string VolT1K1 = "";
string K0 = "";
string K1 = "";
string K2 = "";
double DwOverDt;
string VolT0K0 = "";
string VolT0K2 = "";
double DwOverDy=0;
double DwSqOverDySq = 0;
double YoverW = 0;
double VarianceLoc = 0;
double VolLoc = 0;
// create command
string StrCmd = "SELECT * FROM Table1 WHERE ((strike = @strike_value0 AND strike = @strike_value1 AND strike = @strike_value2) AND (time= @time_value0 AND time= @time_value1)) ";
OleDbCommand Cmd = new OleDbCommand(StrCmd, MyConn);
Cmd.Parameters.Add("@strike_value0", OleDbType.VarChar);
Cmd.Parameters["@strike_value0"].Value = (strike1_run - 0.01).ToString();
Cmd.Parameters.Add("@strike_value1", OleDbType.VarChar);
Cmd.Parameters["@strike_value1"].Value = strike1_run.ToString();
Cmd.Parameters.Add("@strike_value2", OleDbType.VarChar);
Cmd.Parameters["@strike_value2"].Value = (strike1_run + 0.01).ToString();
Cmd.Parameters.Add("@time_value0", OleDbType.VarChar);
Cmd.Parameters["@time_value0"].Value = time0_run.ToString();
Cmd.Parameters.Add("@time_value1", OleDbType.VarChar);
Cmd.Parameters["@time_value1"].Value = (time0_run + 1).ToString();
OleDbDataReader ObjReader = Cmd.ExecuteReader(); // I put a breakpoint here - no issue
if (ObjReader != null) // I put a breakpoint here - no issue
{
int counter = 0;
while ((ObjReader.Read()) && (counter <= 5)) //HERE is the problem: I put a breakpoint here, the cursor just doesn't want to enter the while loop !! I have tried to write just above that statement: "ObjReader.Read()" on its own and it reads it normally, but it doesn't want to read it in the while loop ...
{
value1 = ObjReader.GetValue(1).ToString(); //time column value
value2 = ObjReader.GetValue(2).ToString(); //strike column value
value3 = ObjReader.GetValue(3).ToString(); //vol column value
counter++;
Console.WriteLine("counter= " + counter);
switch (counter)
{
case 1:
K0 = value2;
VolT0K0 = value3;
break;
case 2:
T0 = value1;
K1 = value2;
VolT0K1 = value3;
break;
case 3:
K2 = value2;
VolT0K2 = value3;
break;
case 4:
break;
case 5:
T1 = value1;
VolT1K1 = value3;
Console.WriteLine("Time: " + T0 + " - " + T1 + "\n" + "Strike: " + K0 + " - " + K1 + " - " + K2 + "\n" + "Vol: " + VolT0K1 + " - " + VolT1K1);
break;
default:
break;
}
}
}
ObjReader.Close();
}