473,387 Members | 1,897 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.

Updating Database from Datagrid view (Where is problem. 1 Line of code)

scriptick
Hi,
I am very tired to solve this. I know its very very very easy for beginner level programmers too.
But i am not understanding that where is my problem.

I just wanna update my database with one click only.

I do for update my database from datagridview1 but it shows a error like this :

Unhandled exception has occurred in your application . If you click Continue, the application will ignore this error and attempt to continue.
If you click Quit,the application will close immediately.


Update requires a valid UpdateCommand when passed DataRow
collection with modified rows


Thanks in advanced.
Attached Files
File Type: zip WindowsFormsApplication4.zip (127.2 KB, 92 views)
Jul 12 '13 #1

✓ answered by Dan Effets

This seems to work, let me know if it works for you.
By the way, when updating or adding new data all fields have to be filled or not null .. if one is open it will error out


Expand|Select|Wrap|Line Numbers
  1.  private void btnUpdate_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.             this.Validate();
  5.             this.historyBindingSource.EndEdit();
  6.             this.historyTableAdapter.Update(this.sCHDBDataSet.History);
  7.  
  8.  
  9.  
  10.  
  11.  
  12.         }

2 1510
This seems to work, let me know if it works for you.
By the way, when updating or adding new data all fields have to be filled or not null .. if one is open it will error out


Expand|Select|Wrap|Line Numbers
  1.  private void btnUpdate_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.             this.Validate();
  5.             this.historyBindingSource.EndEdit();
  6.             this.historyTableAdapter.Update(this.sCHDBDataSet.History);
  7.  
  8.  
  9.  
  10.  
  11.  
  12.         }
Jul 13 '13 #2
thank for your reply with code. ok I am checking it
Jul 13 '13 #3

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

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...
0
by: Ben | last post by:
I have a DataGrid in where I have code in the MouseUp Event that checks the area of the Grid clicked, and highlights the entire row. Problem is, that if you the "Right-Click" on another row, it...
3
by: Richard | last post by:
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus will remain on the line in the datagrid they choose to edit. When the user chooses to add a new line in the datagrid,...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
3
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
1
by: radhikabista | last post by:
hey friends , i m not being able to save the updates in datagrid view when i press buttonsave_ gridview i have a class customer with two methods one to get the dataset and other to update database:...
1
by: radhikabista | last post by:
i have a table tbl_client in Ms Access database. my program displays a datagrid view with the search result records. i want to save the changes to data gridview to database.for this i call the...
1
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the...
0
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the...
3
by: newbtemple | last post by:
I keep getting index out of range errors when updating values in a datatable. Please see code below and offer any suggestions on a solution. In general, if the updates are slow, the datagridview...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.