tman43
asked on
How do I cast ADODB.Recordset.Fields values to integers?
I would like to associate the ID's of tableMoose with a range of values from tableBear. The following code gives an "Input string was not in a correct format" error in the If statement. I am having trouble casting the cell values to integers in order to make comparisons in the if statement. The code is ported from VB6 which allowed a cast to integer in the If statement. I am using DotNet 2.0.
Thanks.
Thanks.
private void fill_ID()
{
ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
ADODB.Recordset rs = new ADODB.Recordset();
ADODB.Recordset rs2 = new ADODB.Recordset();
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:" + "\\" + "Foo.mdb", null, null, 0);
rs.Open("Select ID, columnX FROM tableMoose", conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);
rs2.Open("Select ID, columnA, columnB FROM tableBear", conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);
rs.MoveFirst();
while (rs.EOF == false)
{
rs2.MoveFirst();
while (rs2.EOF == false)
{
if ((Int32.Parse((rs.Fields["columnX"].ToString())) >= Int32.Parse((rs2.Fields["columnA"].ToString()))) && (Int32.Parse((rs.Fields["columnX"].ToString())) <= Int32.Parse((rs2.Fields["columnB"].ToString()))))
{
rs.Update("ID", rs2.Fields["ID"]);
}
rs2.MoveNext();
}
rs.MoveNext();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your prompt response and clear solution.
ASKER
Note:
Typo on Line 23.
Should be: ...rs2.Fields["columnB"].. .
Typo on Line 23.
Should be: ...rs2.Fields["columnB"]..
ASKER
Thanks much!
Open in new window