Link to home
Start Free TrialLog in
Avatar of SirReadAlot
SirReadAlot

asked on

OracleDataReader reader vs Dataset

Guys,
just trying to search for data and show the results in the datagrid

this is what i have done, not quite sure wats going on.

when I do a search for records which i know exists, the datagrid would not be filled


private void btnGo_Click(object sender, System.EventArgs e)
            {
                  string connectionString = "server=TTTD.WORLD;User ID=ttt_currency_conversion;Password=ttt_currency_conversion";
                  OracleConnection con = new  OracleConnection(connectionString);
                  string ora =
                        " SELECT GBP_EXCHANGE_PID, ISO_CODE, DATE_STAMP,  EXCHANGE_RATE " +
                        "  FROM GBP_CURRENCY_RATES  " +
                        "  WHERE ISO_CODE LIKE'"  + this.txtFind.Text +"%' ";
                  OracleCommand cmd = new OracleCommand(ora, con);
                  //     cmd.Parameters.Add(":ISO_CODE",txtFind.Text);
         
                  con.Open();
                  OracleDataReader reader = cmd.ExecuteReader();
                  DgExchange.DataSource = reader;
                  DgExchange.DataBind();
                  reader.Close();
                  con.Close();
            }
                
thanks
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Do you have PL/SQL developer installed?

Bob
Avatar of SirReadAlot
SirReadAlot

ASKER

nope
am using toad fornt end.
don't know if that answers the question
how do i used a dataset instead
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can run test Select queries in TOAD to make sure that you have the query built correctly.

Bob
tried this, but same errors as before,

wahts "rates"
private void btnGo_Click(object sender, System.EventArgs e)
                        {
                              string connectionString = "server=TTTD.WORLD;User ID=ttt_currency_conversion;Password=ttt_currency_conversion";
                              OracleConnection con = new  OracleConnection(connectionString);
                        string ora =
                  " SELECT GBP_EXCHANGE_PID, ISO_CODE, DATE_STAMP,  EXCHANGE_RATE " +
                  "  FROM GBP_CURRENCY_RATES  " +
                  "  WHERE ISO_CODE LIKE'"  + this.txtFind.Text +"%' ";
               OracleDataAdapter adapter = new OracleDataAdapter(ora, connectionString);
               DataSet ds = new DataSet();
                 adapter.Fill(ds, "Rates");

            DgExchange.DataSource = ds;
            DgExchange.DataMember = "Rates";
            DgExchange.DataBind();

                              con.Close();
                        }
                
What error are you getting?

"Rates" is an arbitrary table name to avoid getting the generic "Table" for the selected table name.

Bob
okay, i guess the problem is from my side then
sorry, its not just retriving the searched value. so the data grid is empty
I HAVE EVEN USED  the orginal table name.

"GBP_CURRENCY_RATES"; but it does not select anything.

does it matter if my datasets, dataviews are created through drag and drop??



private void btnGo_Click(object sender, System.EventArgs e)
                        {
                              string connectionString = "server=TTTD.WORLD;User ID=ttt_currency_conversion;Password=ttt_currency_conversion";
                              OracleConnection con = new  OracleConnection(connectionString);
            
                              string ora =
                  " SELECT GBP_EXCHANGE_PID, ISO_CODE, DATE_STAMP,  EXCHANGE_RATE " +
                  "  FROM GBP_CURRENCY_RATES  " +
                  "  WHERE ISO_CODE LIKE'"  + this.txtFind.Text +"%' ";

                  OracleDataAdapter oraDataAdatper = new OracleDataAdapter(ora, connectionString);
               //OracleDataAdapter adapter = new OracleDataAdapter(ora, connectionString);
             oraDataSet ds = new oraDataSet();
         //      DataSet ds = new DataSet();
                 oraDataAdatper.Fill(ds, "GBP_CURRENCY_RATES");
                                
            DgExchange.DataSource = ds;
            DgExchange.DataMember = "GBP_CURRENCY_RATES";
            DgExchange.DataBind();

                              con.Close();
                        }
                
the  query string is very correct.
Did you run the resulting query from TOAD to test it?

Bob
yes i did,am it returned a result set.

thanks.
sorry mate,

this doesn't actaully return any data

 SELECT GBP_EXCHANGE_PID, ISO_CODE, DATE_STAMP, EXCHANGE_RATE
 FROM GBP_CURRENCY_RATES
 WHERE ISO_CODE LIKE 'X%'

thanks
tried this on toad
and it worked
 SELECT GBP_EXCHANGE_PID, ISO_CODE, DATE_STAMP, EXCHANGE_RATE
 FROM GBP_CURRENCY_RATES
 WHERE ISO_CODE LIKE '%G%'