[OperationContract]
public List
{
DataClassesDBDataContext db = new DataClassesDBDataContext();
var mlocations = from location in db.locations
select location;
return mlocations.ToList();
}
}
}
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Benjamin KemnerRank #7,492 · 240 reputationPosted Jul 14, 2011, 10:14 PM EDT
Priya LingeRank #785 · 2.9K reputationPosted Jul 14, 2011, 10:16 PM EDT
You can display one column from table like following way,
Make one class at service side.
suppose EmplyoeeClass
public class Employee
{
private string _name;
public string Name
{
get{return this._name;}
set{if(this._name!=value){this._name=value;}}
}
}
Use this class here to get column.
[OperationContract]
public List
{
List<Employee> emp = new List<Employee>();
con.Open();
string query = "select Name from EmplyoeeData";
cmd=new sqlcommand(query,con);
dr = cmd.ExecuteReader();
while(dr.Read())
{
var trx = new Employee
{
Name=dr[0].ToString()
}
emp.Add(trx);
}
con.Close();
return emp;
}
}
In Linq To Sql
[OperationContract]
public List
{
List
DataClasses1DataContext db = new DataClasses1DataContext();
var result=from e in db.EmployeeDatas order by e.Name select e.Name;
foreach(string str in result)
{
var trn=new Employee
{
Name = str
};
emplist.Add(trn);
}
return emplist;
}
Please check attached file.
Thanks.