Using a DataAdapter RRS feed

  • Question

  • Hi,
    This i my first attempt to use a data adaptor. I want to load the data in to a datagridview,edit the data in the datagridview and then save it. This is what i have. The loading part works. the saving part not. (Give a warning: the object is not in the right state).

    private string TableName = "GRN_EENHEID";
            private OracleDataAdapter OraDa;
            private DataSet DsEenheid = new DataSet();
            public void grn_eenheid()  //load the data
                dataGridView1.DataMember = TableName;
                // 1. instantiate a new DataSet
                DataSet dsEenheid = new DataSet();
                // 2. instantiate DataAdapter with select command and connection
                using (OracleDataAdapter da = new OracleDataAdapter("select CODE, NAAM from grn_eenheid", this.Conn))
                    // 3.fill in insert, update, and delete commands
                    OracleCommandBuilder cmdBldr = new OracleCommandBuilder(da);
                    // 4. fill the dataset
                    da.Fill(dsEenheid, TableName);
                    DsEenheid = dsEenheid;
                    OraDa = da;
                dataGridView1.DataSource = dsEenheid;
    private void button7_Click(object sender, EventArgs e)  //save the data
                OraDa.Update(DsEenheid, TableName);

    What is wrong?

    Greatings, Hans

    Saturday, February 1, 2020 4:40 PM


  • Found it

    private string TableName = "GRN_EENHEID";
    OracleDataAdapter _dataAdapter = null;
    public void grn_eenheid()
                _dataAdapter = new OracleDataAdapter();
                _dataAdapter.SelectCommand = new OracleCommand("select CODE, NAAM from grn_eenheid", this.Conn);
                OracleCommandBuilder cb = new OracleCommandBuilder(_dataAdapter);
                DataSet ds = new DataSet();
                _dataAdapter.Fill(ds, TableName);
                dataGridView1.DataSource = ds.Tables[0];
    private void button7_Click(object sender, EventArgs e)
                DataTable dt = dataGridView1.DataSource as DataTable;

    • Marked as answer by HansvB69 Saturday, February 1, 2020 5:51 PM
    Saturday, February 1, 2020 5:51 PM