(Vishy)
7/31/2002 2:00:00 AM
I display Oracle 8 data in an ASP.NET DataGrid server control, using
the ODBC.NET Data Provider. I use a separate Web Form with a single
direct OdbcCommand to insert new rows in my table successfully.
However, whenever I make changes to the DataGrid (and the DataSet
backing it), such as edit or delete a row, the DataSet changes are
never reflected in the database. There are no exceptions thrown and
everything seems to run fine, but the data in the data store remains
unaffected.
Here's my code:
DataSet ds;
OdbcDataAdapter da;
OdbcCommandBuilder cmdBuilder;
//...
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
ds = (DataSet) Session["DataSet"];
da = (OdbcDataAdapter) Session["DataAdapter"];
// All columns [COL1-COLN] in table1 & table2
// are displayed and modifiable. COL1 is a primary key column
da.SelectCommand = new OdbcCommand("SELECT * FROM table1, table2");
cmdBuilder = new OdbcCommandBuilder(da);
DataGrid1.DataSource = ds;
// Updating rows in DataSet
// Locate DataSet row corresponding to DataGrid item
DataRow drChanged = ds.Tables[0].Rows[e.Item.DataSetIndex];
// Assign values from the datagrid to the datarow in the dataset
drChanged.BeginEdit();
drChanged["COL1"]=((TextBox)e.Item.Cells[1].Controls[0]).Text;
// similarly, change COL2 through COLN
drChanged.AcceptChanges();
// Sync DataSet with the data source
da.Update(ds);
// Put the row out of edit mode and rebind to data source
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
Any advice would be much appreciated. I have spent endless hours on
this already.
Thanks,
Vishy.