Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How to over come Repeted Value in Sp List?

  Asked By: Tara    Date: Jun 17    Category: Sharepoint    Views: 1147

I have written a console application which fetch data from database and put it on the list.

My list has following fields. And currently showing following information (Sample)

Name Reporting Designation Project Date

Awdhesh x PC Xy 9/10/2009

Raju x PC Xy 2/10/2009

Arachana v PM Sio 9/10/2009

Arachana v PM Dio 4/12/2010

Arachana v PM Sion 3/30/2010

Praveen Vx PC Cio 9/21/2009

Praveen Vx PC kio 4/21/2010

Praveen Vx PC Rio 12/21/2009

I want to print it in following Format

Name
Reporting
Designation
current Project
Date
Additional
Awdhesh
x
PC
XY
9/10/2009

Raju
x
PC
Xy
2/10/2009


Arachana
v
PM
Dio
4/12/2010
Sio : 9/10/2009
Sion : 3/30/2010
Praveen
Vx
PC
Kio
4/21/2010
Cio : 9/21/2009
Rio : 12/21/2009

Name , Reporting , Designation are not going to change in any case.

Simply I want to put repetitive Project and date in Additional Column and want to show that latest one with respect to date.

How to take datatable loop for that.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Alisha Holmes     Answered On: Jun 17

Try following code :


using



(SPSite site = new SPSite(strDashListRoot))

{



using (SPWeb web = site.OpenWeb())

{



SPList list  = web.Lists["Team"];



foreach (DataRow dr in DsTeam.Tables[0].Rows)

{



SPQuery spQ = new SPQuery();

spQ.Query =

string.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", dr["EmployeeName"]);



SPListItemCollection collection = list.GetItems(spQ);



if (collection.Count == 0)

{



SPListItem item = collection.Add();

item[

"Team Member Name"] = dr["EmployeeName"].ToString();

item[

"Reporting To"] = dr.ItemArray.GetValue(1).ToString();

item[

"Designation"] = dr["DesignationName"].ToString();

item[

"Current Project"] = dr["ProjectName"].ToString();




item[

"Resource End Date"] = dr["ExpectedEndDate"].ToString();



if (Convert.ToInt32(dr["IsResourceBillable"]) == 1)

{

item[

"Is Billable"] = "Yes";

}



else

{

item[

"Is Billable"] = "No";

}

item[

"Status on Project"] = dr["ResourceStatus"].ToString();

item.Update();

}



else if(collection.Count == 1)

{

i++;



Console.WriteLine(i);



if (i < RowCount)//Row Count Has Total Number of Rows in database

{



DataRow dtrow = DsTeam.Tables[0].Rows[i];



if (dr["EmployeeName"].ToString() == dtrow["EmployeeName"].ToString())

{

Info += dr[

"ProjectName"].ToString();

Info +=

":";

Info +=

Convert.ToDateTime(dr["ExpectedEndDate"].ToString()).ToShortDateString();

Info +=

"\n\n";



}



else

{



SPListItem item = collection[0];

item[

"Team Member Name"] = dr["EmployeeName"].ToString();

item[

"Reporting To"] = dr.ItemArray.GetValue(1).ToString();

item[

"Designation"] = dr["DesignationName"].ToString();

item[

"Current Project"] = dr["ProjectName"].ToString();

item[

"Resource End Date"] = dr["ExpectedEndDate"].ToString();



if (Convert.ToInt32(dr["IsResourceBillable"]) == 1)

{

item[

"Is Billable"] = "Yes";

}

else

{

item[

"Is Billable"] = "No";

}

item[

"Status on Project"] = dr["ResourceStatus"].ToString();

item[

"Additional Information"]=Info;

Info =

string.Empty;

item.Update();

}

}

}

}

}

}

 
Didn't find what you were looking for? Find more on How to over come Repeted Value in Sp List? Or get search suggestion and latest updates.




Tagged: