.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 3.00 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 10th, 2006, 01:07 AM
Swapnil Palande Swapnil Palande is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 Swapnil Palande User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 38 sec
Reputation Power: 0
Question Update table in database through datagridview in winform

Hi all,

Please help me in solving following query:

I want to update table at backend in database throughmakeing changes in datagridview.

What I want is, when User makes changes in datagridview and clicks save or update button, the changes which are made in datagridview should get reflect in table in databse.

For ex:

I am having "Datagridview", "Edit" and "Save" button on WinForm and table "EmpDetails" at backend in databse. I am filling "Datagridview" with table "EmpDetails". When user clicked "Edit" button he should allowed to make changes in "Datagridview". After making changes in "Datagridview" when user clicked "Save" button, whichever changes made in datagridview should get reflect at backend in table "EmpDetails".

Reply With Quote
  #2  
Old May 10th, 2006, 05:40 AM
handshakeit handshakeit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: Noida/India
Posts: 127 handshakeit User rank is Private First Class (20 - 50 Reputation Level)handshakeit User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 14 h 14 m 31 sec
Reputation Power: 8
Use this code to populate datagridview

SqlDataAdapter da=new SqlDataAdapter("select * from product",strcon);
SqlCommandBuilder cb=new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource=ds.Tables[0];

//now u can save changes to back end with
da.Update(ds);

Reply With Quote
  #3  
Old May 12th, 2006, 05:47 AM
Swapnil Palande Swapnil Palande is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 Swapnil Palande User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 38 sec
Reputation Power: 0
In case of joins in dataset what is the solution

Thanks

It is working fine if there is single table in dataset.

But in my dataset there are 4 table with join (i.e. to fill datagrid I am combining data from 4 tables by using joins). So what should I do in this case?

Thanks & regards,

Swapnil

Reply With Quote
  #4  
Old May 12th, 2006, 06:39 AM
Hugh of Borg's Avatar
Hugh of Borg Hugh of Borg is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: Switzerland
Posts: 1,152 Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level)Hugh of Borg User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 19 h 1 m 52 sec
Reputation Power: 1900
Hi. I'm working with that right now. I'm new to this so there may be a better solution than this:

Make a DataAdapter for each Table (ie. Customers and Orders).
For filling the dataset:
Code:
adapterCustomers.Fill(myDataSet, "Customers");
adapterOrders.Fill(myDataSet, "Orders");


For updating the Database:
Code:
adapterCustomers.Update(myDataSet, "Customers");
adapterOrders.Update(myDataSet, "Orders");


If your DataSet or your Database enforce some Relations you have to call the Fill and Update methods accordingly.
I also had the problem of errors occuring when i altered the primary key of a line in the dataset. That can be solved by making the primaryKey column uneditable.
Comments on this post
handshakeit agrees: I think there will be other solutions also but can't say those would be better....

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Update table in database through datagridview in winform

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap