By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,898 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,898 IT Pros & Developers. It's quick & easy.

Using a web service to bind data to datagridview and have updates

CroCrew
Expert 100+
P: 563
First off I would like to thank anyone that helps me with this.

What I am trying to do is populate a Datagridview (Windows Forms Application) from a web service.

First thing is to have a button’s onclick event populate the Datagridview and that I got working by having the web service return a dataset and bind it to the Datagridview.

The second thing is to have any changes that is done by the user in the Datagridview saved back to the database (MS-SQL) using another buttons onclick event.

Again any help/examples that you can post here would be very helpful.

Here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. namespace MainEvent
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         ServiceReference1.WebService DoThis = new ServiceReference1.WebService();
  6.         DataSet ds;
  7.  
  8.         //First button.
  9.         private void btnFindAttendee_Click(object sender, EventArgs e)
  10.         {
  11.             ds = new DataSet();
  12.             ds = DoThis.BuildFindAttendeesList();
  13.             //dgvFoundRegisteredAttendees is the id of the Datagridview.
  14.             dgvFoundRegisteredAttendees.DataSource = ds.Tables[0];
  15.         }        
  16.  
  17.         //Second button.
  18.         public void btnSaveAttendeesInformation_Click()
  19.         {
  20.             // ?????
  21.         }
  22.     }
  23. }    
  24.  
Apr 21 '16 #1

✓ answered by CroCrew

Thanks {Mike D.} for your help on this. Working code below...

Expand|Select|Wrap|Line Numbers
  1.  
  2. namespace MainEvent
  3. {
  4.     public partial class Form1 : Form
  5.     {
  6.         ServiceReference1.WebService DoThis = new ServiceReference1.WebService();
  7.         DataSet ds;
  8.  
  9.         //First button.
  10.         private void btnFindAttendee_Click(object sender, EventArgs e)
  11.         {
  12.             ds = new DataSet();
  13.             ds = DoThis.BuildFindAttendeesList(); // This is the function from the web service that returns a dataset.
  14.  
  15.             //dgvFoundRegisteredAttendees is the id of the Datagridview.
  16.             dgvFoundRegisteredAttendees.DataSource = ds;
  17.             dgvFoundRegisteredAttendees.DataMember = "myData";
  18.         }        
  19.  
  20.         //Second button.
  21.         private void btnSaveAttendees_Click(object sender, EventArgs e)
  22.         {
  23.             DataSet ds = (DataSet)dgvFoundRegisteredAttendees.DataSource;
  24.             DataSet dsChanges = ds.GetChanges();
  25.             ds.Merge(DoThis.UpdateAttendeesList()); // This is the function from the web service that updates using a dataset that is passed in.
  26.         }
  27.     }
  28. }    
  29.  
  30.  

Share this Question
Share on Google+
1 Reply


CroCrew
Expert 100+
P: 563
Thanks {Mike D.} for your help on this. Working code below...

Expand|Select|Wrap|Line Numbers
  1.  
  2. namespace MainEvent
  3. {
  4.     public partial class Form1 : Form
  5.     {
  6.         ServiceReference1.WebService DoThis = new ServiceReference1.WebService();
  7.         DataSet ds;
  8.  
  9.         //First button.
  10.         private void btnFindAttendee_Click(object sender, EventArgs e)
  11.         {
  12.             ds = new DataSet();
  13.             ds = DoThis.BuildFindAttendeesList(); // This is the function from the web service that returns a dataset.
  14.  
  15.             //dgvFoundRegisteredAttendees is the id of the Datagridview.
  16.             dgvFoundRegisteredAttendees.DataSource = ds;
  17.             dgvFoundRegisteredAttendees.DataMember = "myData";
  18.         }        
  19.  
  20.         //Second button.
  21.         private void btnSaveAttendees_Click(object sender, EventArgs e)
  22.         {
  23.             DataSet ds = (DataSet)dgvFoundRegisteredAttendees.DataSource;
  24.             DataSet dsChanges = ds.GetChanges();
  25.             ds.Merge(DoThis.UpdateAttendeesList()); // This is the function from the web service that updates using a dataset that is passed in.
  26.         }
  27.     }
  28. }    
  29.  
  30.  
Apr 25 '16 #2

Post your reply

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