Updating datasource from a DataGrid filled with join statement

M

Markus Heid

Hi,
I've got following problem: I'm filling a DataGrid with a data retrieved
from a join statement. The user can insert new lines into the grid or
manipulate existing ones. My question is how can i write that changements
back into the database if I have to insert values into several pages?
Inserting a stored procedure into the database which takes care of that is
not an option.

Thanks in Advance

Markus

P.S Here's my related code

private System.Data.DataSet LoadInternal()
{

System.Data.DataSet setGrid = null;

try

{

string sSql = "select st.pk_id, st.item, st.status, st.type, ge.x, ge.y,
ge.dx, ge.dy from store as st inner join geometry as ge on ge.pk_id =
fk_geo_id";

OleDbCommand cmd = new OleDbCommand();

cmd.Connection = m_conn;

cmd.CommandText = sSql;

OleDbDataAdapter adapter = new OleDbDataAdapter( cmd );

setGrid = new System.Data.DataSet();

adapter.Fill( setGrid, "Store" );

setGrid.Tables[0].RowChanged += new System.Data.DataRowChangeEventHandler(
RowChanged );

adapter.Update

adapter = null;

}

catch( System.Data.OleDb.OleDbException odex )

{

System.Diagnostics.Trace.WriteLine( odex.Message );

}

return( setGrid );

}



private void Row_Changed(object ob, DataRowChangeEventArgs e)

{

//What to do here?

DataTable t = (DataTable) ob;

System.Diagnostics.Trace.WriteLine( t.Columns["pk_id"].ToString() );

Console.WriteLine("RowChanged " + e.Action.ToString() + "\t" +
e.Row.ItemArray[0]);

}
 
M

Miha Markic

Hi Markus,

If this is a 1-1 relation (where data for both rows always exist) it
shouldn't be a big problem.
You'll have to write two OleDbDataAdapters - one for each table (including
fields that are part of each table).
First execute Update for parent table and then for child table.

If this is not a relation mentioned above - you'll have to manually fire sql
stataments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top