Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi developers
I am writing a replace method for a dataset to replace wildcards or regular expression from a csv file which is loaded in dataset .
foreach (DataRow datarow in dataset.Tables[0].Rows)
{
  foreach (DataColumn datacol in dataset.Tables[0].Columns)
  {
    datarow[datacol] = Regex.Replace(datarow[datacol].ToString(), comma.ToString(), slash.ToString());
    datarow[datacol] = Regex.Replace(datarow[datacol].ToString(), colon.ToString(), Blank.ToString());
  }
}

This method is working good but after replacing wildcards or a regular Expression an error is thrown.
"Input string was not in a Correct format ,Could not Store ??? in PRIORITY Column. Expected type Int32"
Please solve the problem that is raised in the code.
Posted
Updated 18-Nov-10 23:43pm
v2
Comments
Manfred Rudolf Bihy 19-Nov-10 5:48am    
@JF2015: Thanks for reformatting the code block. How can this be done? (I mean the editing, as I can't see any edit button on the messages except for my own answers)
Toli Cuturicu 19-Nov-10 13:58pm    
You don't have enough reputation points to be allowed to edit other people's posts. I do have, so I may edit them.

1 solution

Hi Vishu!

Your code converts everything to a string. When you write back to the datarow
you'll run into issues when a column contains an int or a float. As the error message is telling you, it expected type Int32.

What I'd do in your case is to check the column type and only do the conversion to string and the replacing part in case of a character based column type.

Cheers

Manfred
 
Share this answer
 
v3
Comments
JF2015 19-Nov-10 6:54am    
You have an Editor score of 32 - you need at least 100 to edit other people questions.
Manfred Rudolf Bihy 19-Nov-10 7:44am    
Where do I earn editor points?
Henry Minute 19-Nov-10 9:02am    
Manfred, can you see the 'Improve Question' and 'Improve Answer' widgets, bottom right of Question/Answer? That is the 'Edit' button.
Manfred Rudolf Bihy 19-Nov-10 9:05am    
@Henry: JF2015 told me I don't have enough points to edit other peoples questions (As stated above I can edit my own answers). I'd like to know how editor points are earned.
Manfred Rudolf Bihy 19-Nov-10 9:18am    
Ok. I've found the page with all the information how points are awarded in each of the categories. Thanks everybody!

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