471,310 Members | 1,058 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Updating a Datagrid

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
0 1175

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by junglist | last post: by
reply views Thread by cwbp17 | last post: by
reply views Thread by Mike P | last post: by
2 posts views Thread by marcmc | last post: by
2 posts views Thread by =?Utf-8?B?VmFuZXNzYQ==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.