Manage a dataset from web services

Hi,

I have a dataset in a windows forms that retrieves data from a DataBase, and i want to update, delete and add rows. I have to use Web Services, how can I do it

Thanks in advance.



Answer this question

Manage a dataset from web services

  • Milis

    This is how i do it.

    I need to use WebServices to retrieve information out of a database, so that my PDA can access the information. I don't want the PDA to have direct access to the Database so i use Webservices.
    So there are 2 parts, The webservice code and the code on the winforms client

    Webserivce code to send database information:

    [WebMethodAttribute]
    public DataSet SendEvents()
    {
    DataSet returnds;
    returnds = Code to execute stored procedure
    returnds.DataSetName = "CorporateEventTree"; //i name the dataset to make it simple
    returnds.Tables["Table"].TableName = "Event"; //i name the table that came out of it for easy reference as i have multiple tables in the dataset in the other methods. using a .XSD file would be preferable

    return
    returnds;
    }

    Webserivce code to update database

    [WebMethodAttribute]
    public bool UploadEntityListFromDevice(DataSet ds)
    {
    //Convert the Dataset into XML and set it as a parameter
    System.Data.SqlClient.SqlParameter[] e = new System.Data.SqlClient.SqlParameter[1];
    e[0] = new System.Data.SqlClient.SqlParameter("@XMLDOC", ds.GetXml()); //I send XML documents to my stored procedures and then update the entire thing in one call, instead of calling a stored procedure once per record in the dataset
    try
    {
    //Send the XML dataset into the stored procedure. Your code to call SQL update will probably be different, i just left my code here as an example
    GSM.Data.SQLServer.executeStoredProcedure(@"dbo.sEntityReupload",
    GSM.
    Conversion.Strings.encode("user id=xxx;data source=xxx;initial catalog=xxx;password=xxx"), e);
    }
    catch (Exception)
    {
    return false;
    }
    return true;
    }

    Code on Device to Retrieve dataset

    private void button2_Click(object sender, System.EventArgs e)
    {
    WSEventsversion1.
    Version1 WSEMUversion1proxy;//what i called my webservice, yours is bound to be different
    WSEMUversion1proxy =
    new EMU_PDA.WSEMUversion1.Version1();

    DataSet EntityDS =WSEMUversion1proxy.RetrieveEntityList("12345");//actualy invoke the webservice, tada, you have the dataset now ready to use!!
    }

    alternatively, you could probably just go to datasource, and add a datasource from a webservice, and then you'll be able to just drag&drop onto your form

    Code on device to send dataset

    private void uploadActivityForEvent_Click(object sender, EventArgs e)
    {
    DataSet
    myDataset;
    myDataset = whichever dataset you want;

    WSEMUversion1.
    Version1 WSEMUversion1proxy; //Create a variable to hold WS connection
    WSEMUversion1proxy =
    new EMU_PDA.WSEMUversion1.Version1(); //instantiate it
    WSEMUversion1proxy.DeviceEMUTreeUpload(myDatset); //invoke the web service
    }

    I hope that helped you out or gave you some direction


  • Arik

    pass the dataset from win form to web method as an input parameter.Use the dataset to update the data in the database.

    Thanks

    Manish



  • Manage a dataset from web services