Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am retrieving record from a field in the database, the format of the field record is: Attr_8964_1, the first two parts remains the same, but the last part is auto incremented i.e. 1,2,3, etc, how can i split to get the last auto incremented part while retrieving with data reader?

i tried using list, but didnt know how, below is my code:

C#
listAttributeRegion.Add(reader["RegionName"].ToString().Split("_"));

but it is not working, any assistance will be apprciated.

Thanks in advance
Posted
Comments
joshrduncan2012 20-Jun-14 11:40am    
Can you show us why this isn't working and what you should be getting?
Uwakpeter 20-Jun-14 11:47am    
The error message is:Aurgument type string is not assignable to parameter type char,

ListAttributeRegion is a list, this is how i declare it: var listAttributeRegion = new List<string>();
Jafarinejadvazifehkhorani 20-Jun-14 11:57am    
as I mentioned in the solution you should change "_" to '_'

1 solution

if you are sure that all the values have the same format you could use the following code instead of yours

C#
listAttributeRegion.Add(reader["RegionName"].ToString().Split('_')[2]);


for more information about String.Split reer to this link
http://msdn.microsoft.com/en-us/library/b873y76a(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Uwakpeter 20-Jun-14 11:58am    
Thanks it works, i really appreciate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900