473,387 Members | 1,757 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,387 software developers and data experts.

Editing the records in database via DataGridView

18
Hi frnds,
I am working on a project in which one of the form has a datagridview, I was successful in retrieving the table from the database.Now that I want to edit the records on this datagrid and save them back in the physical database.I have been try to do this in a number of ways but getting some or other error pops up.
The following is the code I have used.

myUpdateCommand.CommandText = @"UPDATE Inventory SET ItemDescription = ?, ItemNumber = ?, ItemCode = ?, ItemType = ?, Location = ?, Unit = ?, OurPrice = ?, StudentPrice = ?, PONumber = ?, Quantity = ? WHERE (ItemDescription = ?) AND (ItemNumber = ?) AND (ItemType = ?) AND (Location = ?) AND (Unit = ?) AND (OurPrice = ?) AND (StudentPrice = ?) AND (PONumber = ?) AND (Quantity = ?)";
this.myUpdateCommand.Connection = this.myOleDbConnection;
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemDescription",this.dataGridView 1.CurrentRow.Cells[0].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemNumber",this.dataGridView1.Cur rentRow.Cells[1].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemCode",this.dataGridView1.Curre ntRow.Cells[2].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemType",this.dataGridView1.Curre ntRow.Cells[3].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("Location",this.dataGridView1.Curre ntRow.Cells[4].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("DateItemCreated",this.dataGridView 1.CurrentRow.Cells[5].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("Unit",this.dataGridView1.CurrentRo w.Cells[6].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("OurPrice",this.dataGridView1.Curre ntRow.Cells[7].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("StudentPrice",this.dataGridView1.C urrentRow.Cells[8].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("PONumber",this.dataGridView1.Curre ntRow.Cells[9].Value.ToString()));

this.myUpdateCommand.Parameters.Add(new OleDbParameter("Quantity",this.dataGridView1.Curre ntRow.Cells[10].Value.ToString()));
this.myOleDbDataAdapter.UpdateCommand = myUpdateCommand;

DataSet myChangedDataSet = myDataSet.GetChanges();
this.myDataSet.GetChanges();
btnSave.Enabled = false;
this.myOleDbDataAdapter.Update(myDataSet, "Inventory");

Could someone help me out with this and let me know what statement is causing the problem or is it the entire technique thats causing the problem?

Thank You in advance!!!
Feb 6 '07 #1
1 4053
kenobewan
4,871 Expert 4TB
Your update statement is not going to work, because you are trying to set values to a record and identify the record using those values which don't exist in the database. Do you have a unique identifier in the database? This is usually an id number and you usually update the record using this as the sole identifier - Where uniqueID = thisUniqueID...

Hope that this helps.
Feb 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: news.microsoft.com | last post by:
Hi guys, I have a problem with the DataGridView. I want to catch the value of a cell when the user is editing it. Actually, I can't figure if there is an event or a property to get this value. ...
0
by: ME | last post by:
I have an application that displays data in a DataGridView. The data is in a DataView that is sorted and at times filtered. One of the columns I have in the dataview is a boolean field called...
1
by: =?Utf-8?B?TWF6?= | last post by:
I have a datagridview (Winforms vb.net) whose datasource is a class I have constructed. I want to allow users to edit the cells in the grid and I can't. The MS documentation states that for this to...
1
by: kristian | last post by:
Hi all I have a simple form with not much more than a datagridview control, and want to show and edit the contents of a table in my mysql table. So far I have managed to set the db table as a...
0
by: Ronald S. Cook | last post by:
We're using a DataGridView in a Windows app and have paging turned on. The SELECT proc that is called would normally return 1000+ records. We have paging set for 10 records at a time. In this...
1
by: sreenu123 | last post by:
How to insert multiple records into a database table that are entered into a datagridview. With a single shot of Save all the records in the datagridview should be updated using C# . Can any one help...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've been away from web programming for a while and I have a situation that's new to me. I'm using VB/Dot Net 2.0. I've created an xsd (dataset) in the project and dragged some fields from a...
2
by: crownrajesh | last post by:
First of all thanks for all who reply this Question.i have a datagridview with first column as combobox and rest as textbox column. i would like to fill the datagridview manually using c# code for...
6
by: Gun Slinger | last post by:
Hi guys, I have a quick question which i have pondered for a little while. I'm not sure if its even a good idea (so maybe advice on whether or not to do it would be helpful as well). I want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.