I an reading data from a database table. Now I want to store the data in a variable. I need to put conditions depending on the values contained in the columns.
OracleCommand cmd = new OracleCommand("select user_name,parameter_name,parameter_value from table1 where user_name ='USER'", ocConnection);
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr["PARAMETER_NAME"].ToString() =="NAME1")
{
class1.Value1 = Convert.ToInt32(dr["PARAMETER_VALUE"].ToString());
}
if ((dr["PARAMETER_NAME"].ToString()) == "NAME2")
{
class1.Value2 = Convert.ToInt32(dr["PARAMETER_VALUE"].ToString());
}
dr.close();
dr.Dispose();
}
But this gives an error as the control doesn't go inside any of the if blocks. Also gives an error such as :
System.IndexOutofRangeException
unable to find specified column in resultset.
Though the values are there in the table.