469,928 Members | 1,900 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

TROUBLE UPDATING DataGrid cells back to the database

I'm having trouble updating individual datagrid cells.

Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and
car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables have a
FK relationship on CAR_ID

so the oracledataadapter1 select statement(CommandText) is:

select car_master.car_id,
car_master.year,car_master.vehicle,car_detail.car_ id AS EXPR1,
car_detail.price,car_detail.mileage,car_detail.bod y,car_detail.body FROM
car_master,car_detail where car_master.car_id=car_detail.car_id;
the Foreign Key relationship I used:
alter table car_detail add constraint detailFK(CAR_ID) references

The c# DataGrid updatecommand code:

TextBox tb;

string key = dgDTMgmt.DataKeys[e.Item.ItemIndex].ToString();
//Year column
tb = (TextBox)e.Item.Cells[1].Controls[0];
string stYr = tb.Text.Trim().ToString();

//Vehicle column
tb = (TextBox)e.Item.Cells[2].Controls[0];
string stVhcle = tb.Text.Trim().ToUpper();

TextBox price = (TextBox)e.Item.FindControl("txtPrice");

string stPrice = price.Text;
//decimal pr = Convert.ToDecimal(stPrice);
//string stPriceVal = pr.ToString();

//Mile column
tb = (TextBox)e.Item.Cells[5].Controls[0];
string dMile = tb.Text;

//Body column
tb = (TextBox)e.Item.Cells[6].Controls[0];
string strBody = tb.Text.Trim().ToUpper();

string sql = "update car_detail set PRICE ='" + stPrice + "',MILEAGE='" +
dMile + "',BODY= '" + strBody + "' where car_id = " + key;

if (oracleConnection1.State == ConnectionState.Closed)
OracleCommand cmd = new OracleCommand(sql,oracleConnection1);
catch (Exception ex)

String sql2 = "update car_master set YEAR = '" + stYr + "',VEHICLE= '" +
stVhcle + "' where car_id = " + key;

if (oracleConnection1.State == ConnectionState.Closed)

OracleCommand cmd2 = new OracleCommand(sql2,oracleConnection1);
catch (Exception ex)

if (oracleConnection1.State==ConnectionState.Open)
//DataGrid Non-Editable Mode
DataGrid1.EditItemIndex = -1;


I'm having trouble updating just the price column. The only way to update
the price column is if the user edits several columns and then the price
column updates.

I want the user to be able to update a single column at a time and not have
to update multiple columns at the same time.

I don't know what I'm doing wrong. I'm thinking that my select commandtext
statement is the problem.

Any suggestions would be greatly appreciated.

If there are better ways of updating individual datagrid cells back to the
database, please provide some c# code examples.



Nov 19 '05 #1
0 1460

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by cwbp17 | last post: by
1 post views Thread by Harry Devine | last post: by
3 posts views Thread by Jon Agiato | last post: by
5 posts views Thread by junglist | last post: by
1 post views Thread by jason | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.