473,699 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,MI LEAGE,and BODY);both tables have a
FK relationship on CAR_ID

so the oracledataadapt er1 select statement(Comma ndText) is:

select car_master.car_ id,
car_master.year ,car_master.veh icle,car_detail .car_id AS EXPR1,
car_detail.pric e,car_detail.mi leage,car_detai l.body,car_deta il.body FROM
car_master,car_ detail where car_master.car_ id=car_detail.c ar_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.DataKe ys[e.Item.ItemInde x].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("t xtPrice");

string stPrice = price.Text;
//decimal pr = Convert.ToDecim al(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 (oracleConnecti on1.State == ConnectionState .Closed)
{
oracleConnectio n1.Open();
}
OracleCommand cmd = new OracleCommand(s ql,oracleConnec tion1);
cmd.ExecuteNonQ uery();
}
catch (Exception ex)
{}

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

try
{
if (oracleConnecti on1.State == ConnectionState .Closed)
{
oracleConnectio n1.Open();
}

OracleCommand cmd2 = new OracleCommand(s ql2,oracleConne ction1);
cmd2.ExecuteNon Query();
}
catch (Exception ex)
{}

finally
{
if (oracleConnecti on1.State==Conn ectionState.Ope n)
{
//DataGrid Non-Editable Mode
DataGrid1.EditI temIndex = -1;
oracleDataAdapt er1.Fill(dsCarL ist1);
DataGrid1.DataB ind();
oracleConnectio n1.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 1635

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

Similar topics

0
1298
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 the database? I've used the following code for the DataGird1_UpdateCommand Option1
1
3778
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 Yes/No value in Access. Using the OleDbCommand, if I do not consider the Yes/No field, the ExecuteNonQuery command, using my UPDATE SQL statement, updates the record correctly. However, if I put the Yes/No field into the mix, ExecuteNonQuery...
3
1796
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 information to another object which forms an SQL query and makes the query to the DB (actually to a DBFacade object). In any case, please see the code I have listed below for my update DataGrid event. With this code, the DB is updated using the old...
5
2031
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 one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
1
1537
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 access DB via a datagrid control. The add and delete functions work great, but the edit does not actually update the database. I put in some displays and apparently on the first item in the grid gets set during editing, all others come back empty???
13
2647
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. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the field/cell that is filled by the javascript appears to be blank in my update code, even though I can...
2
1672
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 changes made to cells in the datagrid call an update on the corresoonding data within a database? I've looked in vain for a really simple way to do this with minimal coding, but I'm coming to the conclusion that I will have to trap the events of...
3
1265
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 to a specific database using a MySQLConnection. my problem now is that i want a user to actually enter some data into the datagrid and the data entered by the user should be reflected in the database(or the database should be updated with the new...
4
1761
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 dgr in dgScanItems.Rows) { if (Convert.ToBoolean(dgr.Cells.Value) == true) {
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8897
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6549
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.