473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 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 1620

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 approach on updating a row from the datagrid back to...
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 update that last 4 fields. The last field is a...
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, so everytime I make a change I send the cell...
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. However what used to happen was that once i updated...
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 it to maintain a small local Microsoft 2000...
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, another cell in the datagrid is filled with a value....
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 plain datagrid to a database in such a way that...
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 windows form and that datagrid's datasource is bound...
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 when it is selected. foreach (DataGridViewRow...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.