Saturday, March 31, 2012

string to string[]

string[] strArray;while(dtardrUsrDet.Read())

{

string strUsrEmail=dtardrUsrDet.GetValue(0).ToString();

int intDayDiff=System.Convert.ToInt16(dtardrUsrDet.GetValue(1).ToString());

if(intDayDiff==45)

{

strArray=strUsrEmail;

}

if(intDayDiff==30)

{

strArray=strUsrEmail;

}

how to store string values from reader into string array

Hi,

I am assuming that you want each string in an array, not each character as a separate string in a string array here...

The easiest way is to create an ArrayList, add each string to that (within a while loop to read each record from the DataReader) and then use the ToArray() method, passing the type that you want the array to be (i.e string in your case).

In .net 2.0, you would use a generic List<string> collection, which gives you the advantage of strong typing on the collection.

Rich


string[] strArray;

Int i=0;

while(dtardrUsrDet.Read())

{

string strUsrEmail=dtardrUsrDet.GetValue(0).ToString();

int intDayDiff=System.Convert.ToInt16(dtardrUsrDet.GetValue(1).ToString());

if(intDayDiff==45 ||intDayDiff==30)

{

Array.Resize(refstrArray, i);
strArray[i] =strUsrEmail;

i++;

}

}

hope this helps./.

0 comments:

Post a Comment