Update a Datagrid...better way?

G

Guest

Have two oracle tables that have a FK relationship on ID column.

Have one datagrid that displays all of the columns of both tables.

What's the best approach on updating a row from the datagrid back to the
database?

I've used the following code for the DataGird1_UpdateCommand

Option1
**********
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

TextBox tbSales = (TextBox)e.Item.Cells[1].Controls[0];

string stSale = tbSales.Text;

string sql = "update table1 set Sale = '" + stSale + "' where ID= " + key;

oracleConnection1.Open();
OracleCommand cmd = new OracleCommand(sql,oracleConnection1);
cmd.ExecuteNonQuery();
oracleConnection1.Close();
DataGrid1.EditItemIndex = -1;
oracleDataAdapter1.Fill(dataSet11);
BindDataGrid1();
*******
It doesn't do a great job of updating from the datagrid to the database.
Especially if you have two tables together in one datagrid. I'm looking for a
better approach on updating.

Another way was to use the DataSet:

Option2
*******
DataSet1.DBTableRow row;

row = dataSet11.DBTable.FindByID(int.Parse(key));

row.SALE = stSale;
*****************
Does going the route of option2 offer better performance OR is there a
better way to update the datagrid than the above options? If you could show
some sample c# code that would be appreciated.

Any suggestions would be appreciated.

Thanks.

bebop
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top