dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPhagu Mahato
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » Sharepoint »

How to update the list item values in to the list?


Posted Date: 30 Jun 2012      Posted By:: sridhar     Member Level: Bronze    Member Rank: 2610     Points: 2   Responses: 1



I want on scenario i have Emp list that have fields are Id ,name ,salary .i want update the items in the list programatically? please give me reply for the scenario ASAP...



Responses

#678254    Author: Devaraj T N      Member Level: Gold      Member Rank: 18     Date: 30/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

First create emp class as follows


public class emp
{
//declaring fields
string _id;
string _name;
string _salary;

//declaring properties
public string id
{
get
{
return _id;
}
set
{
_id = value;
}
}

public string name
{
get
{
return _name;
}
set
{
_name = value;
}
}

public string salary
{
get
{
return _salary;
}
set
{
_salary = value;
}
}

}


Add retrieveemplist() method inside the emp class

public List<emp> retrieveemplist()
{
string myconnectionstring = @"Data Source=servername;Initial Catalog=databasename; username=username; password=password;";
SqlConnection con = new SqlConnection(myconnectionstring);
try
{
con.Open();
SqlCommand com = new SqlCommand("select * from emp", con);
SqlDataReader dr = com.ExecuteReader();
List<emp> emplist = new List<emp>();
while (dr.Read())
{
emp emp = new emp();
emp.id = dr["id"].ToString();
emp.name = dr["name"].ToString();
emp.salary = dr["salary"].ToString();
}
com.Dispose();
dr.Dispose();
con.Dispose();
return emplist;
}
finally
{
con.Close();
}
}


Your whole emp class as follows

public class emp
{
//declaring fields
string _id;
string _name;
string _salary;

//declaring properties
public string id
{
get
{
return _id;
}
set
{
_id = value;
}
}

public string name
{
get
{
return _name;
}
set
{
_name = value;
}
}

public string salary
{
get
{
return _salary;
}
set
{
_salary = value;
}
}

public List<emp> retrieveemplist()
{
string myconnectionstring = @"Data Source=servername;Initial Catalog=databasename; username=username; password=password;";
SqlConnection con = new SqlConnection(myconnectionstring);
try
{
con.Open();
SqlCommand com = new SqlCommand("select * from emp", con);
SqlDataReader dr = com.ExecuteReader();
List<emp> emplist = new List<emp>();
while (dr.Read())
{
emp emp = new emp();
emp.id = dr["id"].ToString();
emp.name = dr["name"].ToString();
emp.salary = dr["salary"].ToString();
}
com.Dispose();
dr.Dispose();
con.Dispose();
return emplist;
}
finally
{
con.Close();
}
}
}


Now you can update your emp list by calling retrieveemplist() method from emp class anywhere in the application by declaring as follows.

//Declaring emp class object name employee
emp employee = new emp();
//fetching the emp list from the database
List<emp> emplist = employee.retrieveemplist();



Hope it will be usefull,

Regards,
Devaraj T.N
Senior Software Engineer,
Microsoft Certified Technology Specialist.

Regards,
T.N. THEAAVARAAJ
Senior Software Engineer,
Microsoft Certified Technology Specialist.
Email:devabe2005@gmail.com



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to update the list item values in to the list?
Previous : SharePoint Timer Job Definitions
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.