Reputation: 25
Please check the comment made in the middle of the code, it shows where is the problem and how I try to solve it ... thanks !
The problem is within the statement: "while ((ObjReader.Read()) && (counter <= 5)) ". I put a breakpoint, but 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 ...
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();
}
Upvotes: 0
Views: 850
Reputation: 4029
Probably your query is returning zero rows. This will cause Read() to return false. When dealing with time intervals, it is very easy to get it backwards and get zero rows. The problem is you have two DIFFERENT time values, and you're comparing them to the same column. One column can never be simultaneously equal to two different values! So, you're getting zero rows back. Also, try to avoid using the * in your queries - list only the columns you need and save network overhead.
Your query probably needs to be a RANGE query, not an equals...
string StrCmd = "SELECT time, strike, vol FROM Table1 WHERE ((strike = @strike_value0 AND strike = @strike_value1 AND strike = @strike_value2) AND (time >= @time_value0 AND time <= @time_value1)) ";
Note that you're doing the same thing with the "strike" column - requiring it to be equal to two different values at the same time - if those two values aren't the same, you will always get zero rows back. It's similar to when we say "where 1=0" to force zero rows.
Upvotes: 1