Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Friday, December 02, 2011

Insert a New ListItem into SharePoint List using Server Side Code


SPWeb currentWeb = SPContext.Current.Web;
SPList lstLogin = currentWeb.Lists["Login"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<Where><Eq><FieldRef Name='UserName' /><Value
Type='Text'>"+txtUserName.Text.ToString().ToLower()+"</Value></Eq></Where>";
SPListItemCollection myColl = lstLogin.GetItems(sQuery);
if (myColl.Count > 0)
{
lblMessage.Text = "UserName Already Exists";
}
else
{
SPListItemCollection myColl1 = lstLogin.Items;
SPListItem item = myColl1.Add();
item["UserName"] = txtUserName.Text;
item["PassWord"] = txtPassWord.Text;
item.Update();

No comments:

Post a Comment