Showing posts with label getvalue. Show all posts
Showing posts with label getvalue. Show all posts

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./.

Monday, March 26, 2012

String/Number manip.

In the following line:
txtWage.Text = "$" & Trim(dataReader.GetValue(9).ToString)

It returns $20.0000 I only want it to return back $20.00 -- every search I've done in string manip. has shown me zilch.

Any suggestions?

txtWage.Text = Format(CDbl(Trim(dataReader.GetValue(9).ToString)), "currency")
I think you can use String.Format also to do the same thing, with the format of {0:c}