i am using dataset and retreving the data from MS ACCESS file. It works fine. From that dataset i am putting the value into a string variable as:
string name = dataset.Tables["tablename"].Rows[0]["NAME"];
Now i have to display each character in the name so i am doing it:
for(int i=0; i
But i eg name = "ABC" now the length should be 3 but it is returning 255. Looking for prompt reply.
WaqasPosted May 9, 2008, 5:10 AM
Sorry buddy
Actually it was my mistake. I was calling the indexOf() function on the wrong string variable.
Any how its working fine now.
Thank you very much
AlanPosted May 8, 2008, 3:48 PM
The IndexOf () method shouldn't give -1 if there's an 'e' in the string
Are you sure that it's a lower case 'e' and not a capital 'E'?
Also, as you're using a loop, are you sure that you're considering the correct string?
WaqasPosted May 8, 2008, 4:29 AM
Thanks buddy, it works fine.
Another problem now:
I am again putting the name from the dataset in the string variable and then trying to find the occurance of certain character in that string but its always give -1 (which means that character is not present in the string) although that character is present in the string. Have a look at the code:
for
(int i = 0; i < count; i++){
sindex = 0;
key_select = (string)dataset.Tables["AllRecords"].Rows[i]["NAME"];key_select = key_select.TrimEnd(
' ','\0'); //key_select = 34 Streetsindex = key_select.IndexOf(
"e"); Console.WriteLine(key_select+" "+sindex); //34 Street -1}
//end of loopPlease help me out.
AlanPosted May 7, 2008, 12:51 PM
It sounds like the string is being filled out with spaces or null characters up to the field length. I'd try inserting the following line before you go into the 'for' loop:
name = name.TrimEnd(' ', '\0');