Using a DataAdapter

  • Thread starter Thread starter HansvB69
  • Start date Start date
H

HansvB69

Guest
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

Continue reading...
 
Back
Top