472,353 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
car_master(CAR_ID);

****************************
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();
int.Parse(stYr);

//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;

try
{
if (oracleConnection1.State == ConnectionState.Closed)
{
oracleConnection1.Open();
}
OracleCommand cmd = new OracleCommand(sql,oracleConnection1);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{}

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

try
{
if (oracleConnection1.State == ConnectionState.Closed)
{
oracleConnection1.Open();
}

OracleCommand cmd2 = new OracleCommand(sql2,oracleConnection1);
cmd2.ExecuteNonQuery();
}
catch (Exception ex)
{}

finally
{
if (oracleConnection1.State==ConnectionState.Open)
{
//DataGrid Non-Editable Mode
DataGrid1.EditItemIndex = -1;
oracleDataAdapter1.Fill(dsCarList1);
DataGrid1.DataBind();
oracleConnection1.Close();
}

}
}

**************************
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.

Thanks.

bebop

Nov 19 '05 #1
0 1538

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cwbp17 | last post by:
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...
1
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to...
3
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter,...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row....
1
by: jason | last post by:
The guts of the below asp.net vb code was pieced together from another thread - all due credit to it's original author. Thank you! I've modified...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid,...
2
by: Greg | last post by:
I'm using the Framework 1.1, so I don't have access to the new DataGridView object. What I'm wondering is, is there a really simple way to bind a...
3
by: lemuel | last post by:
hello everyone. i'm new here at this site so sorry if i may sound like a newb (i really am) i'm using C# by the way. i have a datagrid in my...
4
by: DragonLord | last post by:
I have a strange situation, I am looping through a datagrid view and updating the database with the results from each row that is timestamped...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.