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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

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

    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:
    Code:
    namespace MainEvent
    {
        public partial class Form1 : Form
        {
            ServiceReference1.WebService DoThis = new ServiceReference1.WebService();
            DataSet ds;
    		
    		//First button.
    		private void btnFindAttendee_Click(object sender, EventArgs e)
            {
                ds = new DataSet();
                ds = DoThis.BuildFindAttendeesList();
    			//dgvFoundRegisteredAttendees is the id of the Datagridview.
    			dgvFoundRegisteredAttendees.DataSource = ds.Tables[0];
    		}		
    		
    		//Second button.
            public void btnSaveAttendeesInformation_Click()
            {
                // ?????
            }
    	}
    }
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

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

    Code:
    namespace MainEvent
    {
    	public partial class Form1 : Form
    	{
    		ServiceReference1.WebService DoThis = new ServiceReference1.WebService();
    		DataSet ds;
     
            //First button.
    		private void btnFindAttendee_Click(object sender, EventArgs e)
    		{
    			ds = new DataSet();
    			ds = DoThis.BuildFindAttendeesList(); // This is the function from the web service that returns a dataset.
    
    			//dgvFoundRegisteredAttendees is the id of the Datagridview.
    			dgvFoundRegisteredAttendees.DataSource = ds;
    			dgvFoundRegisteredAttendees.DataMember = "myData";
    		}        
    
    		//Second button.
    		private void btnSaveAttendees_Click(object sender, EventArgs e)
    		{
    			DataSet ds = (DataSet)dgvFoundRegisteredAttendees.DataSource;
    			DataSet dsChanges = ds.GetChanges();
    			ds.Merge(DoThis.UpdateAttendeesList()); // This is the function from the web service that updates using a dataset that is passed in.
    		}
    	}
    }

    Comment

    Working...