By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Updating a Datagrid

P: n/a
Have two 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
Jul 26 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.