Page 1 of 1

Need help populating DataGridView to cursor from StoredProc

Posted: Fri 16 Mar 2012 16:22
by bclayshannon
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();

Wrong sample code, but still have the same question

Posted: Fri 16 Mar 2012 16:37
by bclayshannon
Oops, sorry, that was ODP sample code.

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

Posted: Tue 20 Mar 2012 13:54
by Pinturiccio
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.