Need help populating DataGridView to cursor from StoredProc

Need help populating DataGridView to cursor from StoredProc

Postby bclayshannon » Fri 16 Mar 2012 16:22

I'm trying to bind a DataGridView (VS 2010, .NET 4) to the result set from a Stored Proc. I tried to use the sample code in ViewProducts.cs, but DataGridView does not have a SetDataBindings() method.

Here's what I've got - which doesn't work the way I want it to, obviously (I CAN get data via the DataReader, but am not able to populate the DataGridView); what I added today based on the ViewProducts.cs sample code is commented with today's date.

Code: Select all
            oracleCommand1.Parameters.Clear();
            int iFromYear = dateTimePickerFrom.Value.Year;
            int iFromMonth = dateTimePickerFrom.Value.Month;
            int iFromDay = dateTimePickerFrom.Value.Day;
            int iToYear = dateTimePickerTo.Value.Year;
            int iToMonth = dateTimePickerTo.Value.Month;
            int iToDay = dateTimePickerTo.Value.Day;
            oracleCommand1.Parameters.Add("iStartDate", new DateTime(iFromYear, iFromMonth, iFromDay));
            oracleCommand1.Parameters.Add("iEndDate", new DateTime(iToYear, iToMonth, iToDay));
            oracleCommand1.Parameters.Add("iCATEGORYID", 114);

            oracleConnection1.Open();
            OracleDataReader myReader = oracleCommand1.ExecuteReader();
            OracleParameter pRes = new OracleParameter("C_REF", myReader);
            pRes.Direction = ParameterDirection.InputOutput;         
            oracleCommand1.Parameters.Add("c_ref", pRes);

            // added 3/16/2012 - can't figure it out...
            OracleDataAdapter oda = new OracleDataAdapter();
            oda.SelectCommand = myReader.?
            DataSet ds = new DataSet("_ds");
            oda.Fill(ds, "Bla"); //whatever I want to name it, I guess...
            DataGridView1.SetDataBinding(ds, "Bla"); //whatever I want to name it, I guess...
            //< added 3/16/2012

            //dataGridView1.DataSource = myReader.GetValues(5);
            while (myReader.Read())
            {
                MessageBox.Show(myReader.GetString(0)); // + ", " + myReader.GetString(myReader.GetOrdinal("contactemail")));
            }
            myReader.Close();
bclayshannon
 
Posts: 29
Joined: Wed 14 Mar 2012 18:37
Location: Monterey, California

Wrong sample code, but still have the same question

Postby bclayshannon » Fri 16 Mar 2012 16:37

Oops, sorry, that was ODP sample code.

I still need to know how to populate a DataGridView with devConnect, though...
bclayshannon
 
Posts: 29
Joined: Wed 14 Mar 2012 18:37
Location: Monterey, California

Postby Pinturiccio » Tue 20 Mar 2012 13:54

bclayshannon wrote:I still need to know how to populate a DataGridView with devConnect, though...

For populating DataGridView with dotConnect for Oracle you have to bind DataGridView.DataSource with DataTable or DataSet.

There is a simple example how to use DataGridView:
Code: Select all
OracleConnection conn = new OracleConnection("host=orcl1120;user id=scott;password=tiger;");
OracleCommand comm = new OracleCommand("select * from dept", conn);
OracleDataTable dt = new OracleDataTable(comm);
dt.Fill();
dataGridView1.DataSource = dt;


DataReader can't be binded to DataGridView.
Pinturiccio
Devart Team
 
Posts: 1895
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for Oracle