Hello,
In C# .I will Suggest You To Use String.To Count the length Simply Use Spilt Function.
Declare
string sOptInContactsIDs = string.Empty; ;
First Check whether that Column Has value or not.
foreach (DataRow drCont in dt.Rows)
{
if(drCont["ContactID"]!=DBNull.Value)
{
if(sOptInContactsIDs == string.Empty)
sOptInContactsIDs = "'"+ drCont["ContactID"] +"'";
else
sOptInContactsIDs = sOptInContactsIDs +"," +"'"+ drCont["ContactID"] +"'";
}
}
int icount = sOptInContactsIDs.Split(',');
Intially When First Row is Fetched & Value Is 1
then
sOptInContactsIDs="'"+1+"'"= '1'
For Second time assume value is 2
sOptInContactsIDs = '1'+","+"'"+2+"'"='1','2'
If you are aware of string.Format Use that One For Better Exection.
If Possible Use For Loop Instead of ForEach.
I have Used that Code in My Project . i have collected all Ids in Array. Then Using For Loop I have collected the value in string and inserted comma after that.
Hope It Helps You.
Happy Coding :-)