Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, i wanna ask you something.
I have a table that contain some data and i want to load these into IDictionary. How can i do that..??
I'm using oracle as database, and for how i execute sql syntax like this :

C#
public IDictionary<int, string> LOAD_DATA_TEMP_MSGS(string membercode, string status)
    {
      IDictionary<int, string> TEMP = new Dictionary<int, string>();
      oConHandler = new CConnectionHandler();
      try
      {
        oCommand = new OracleCommand(Q_SELECT_ALL_FROM_TABLE(membercode, status), oConHandler.OpenConnAkses());
        oCommand.ExecuteScalar(); // Execute sql syntax
       //-- load into Idictionary 
      //-- How can i do that ???

      }
      catch (Exception ex)
      {
        olog.WriteLogFile("Error while execute load_data_temp_msgs at : " + DateTime.Now.ToString() + "\n" + "Reason : " + ex.Message);
      }
      finally { oConHandler.CloseConnAkses(); }
      return TEMP;
    }


C#
private string Q_SELECT_ALL_FROM_TABLE(string membercode, string status)
{
   string Q_SQL = "SELECT * FROM T_MEMBER WHERE BANKCODE='" + membercode + "' AND STATUS='" + status + "'";

   return Q_SQL;
}
Posted
Comments
Teamsar Muliadi 4-Oct-10 2:52am    
Is anybody can help me please.. :(

1 solution

I don't believe you want to use ExecuteScalar for this. Execute scalar will only return a single value (first column of first row of dataset with everything else being ignored). I think ExecuteReader is what you want.

I think something like this might work:
using(OracleDataReader reader = oCommand.ExecuteReader())  //Instead of oCommand.ExecuteScalar;
{

   while(reader.read)
   {
      TEMP.Add(Convert.ToInt32(reader.Item("{the name of column containing int value}"),reader.Item("{the name of column containing string}").ToString());
   }
}
 
Share this answer
 
v2
Comments
Teamsar Muliadi 4-Oct-10 22:10pm    
thank you cmanderson.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900