WCF/WF - Update data using Webservice. - Asked By kumar on 27-Aug-10 05:18 AM


How to update the data in sql data table using webservice and i am able to retrieve the data using webservice but i dont the query for update.

Please give me a advice.......Thanks in advance.
Reena Jain replied to kumar on 27-Aug-10 05:36 AM
hi kumar,

what you want to update, you want the update query?
kumar replied to Reena Jain on 27-Aug-10 05:41 AM
I retrieve the data in the datagrid ...i want  update the data through the webservice for that i need update query.
Anand Malli replied to kumar on 27-Aug-10 05:48 AM
this question is related to Sql Server rather than WCF...as far as updation of your data is concern the format of update query remains the same

if i understood you properly you want to update the table data of your sql and you want the syntax for update query right...

it goes like following

UPDATE <table name> SET <field name>=<new value> WHERE <field name>=<value>

let me know what you are trying to do...
kumar replied to Anand Malli on 27-Aug-10 06:09 AM

The below method i am using in webservice to retrievet the data and the query is.....

members = from member in db.Members

select member;

----Member is a table in the sql database--------

like this i want to update so i need a update query, how can i do it throug the webservie? kindky help me.Thanks in advance...........

public List<Member> GetMembers()


DataClassesDataContext db = new DataClassesDataContext();

var members = from member in db.Members

select member;

//return list of member objects

return members.ToList();


Anand Malli replied to kumar on 27-Aug-10 06:22 AM
are you using DBML? or using EDMX ? if  yes then you just need to have three layers (DataAccessLAyer  you would be having if you are using DBML or EDMX),now as per your code it seems that you also have Business layer as well as your Member belongs to  that business layer only now what you need to is just following

say your member class is having all properties as your database table fields right,so say your table contains two field called id and name right so your member class would containing two of them propoerty which you would be setting and then just pass the object if this class to your business layer with all property set and call the update method just see below code

your business layer
public class member
   public int id {get;set;}
   public string MemberName {get;set;}

now in your ui where your datagrid is...so i do not know if you have taken edit/update button but in whatever event you have written just set these above property over there like following

var objMember = new Member
  id = txtid.Text.Trim().Replace("'", string.Empty)),
  MemberName = txtMemberName.Text.Trim().Replace("'", string.Empty))

now your properties are set now its time to call the method of your dataaccess layer,i am assuming that you would be having one method for update which would be calling you update SP with required param and it would be taking object of Member as parameter,so that you can have all updated values in it exposed as properties like following

var objMemberUpdate = new MemberManager();

i hope you are getting what i said

just let me know