I apologize for this newbie question, but I’m looking for a simple solution.
I want to write a function that will return a datatable.
Like this:
public static DataTable DataTableCommaReplce(DataTable dt){..}
The function will check each data in DataTable.
If data contained one or more commas, the function will make that data in double quote.
For Example:
you,me⇒"you,me"
What’s the best way to write this function?
Can any body help me?
I had solved with this code, but I want more simple solution.
If possible, I want no looping.
public static DataTable DataTableCommaReplce(DataTable dt)
{
int col = dt.Columns.Count;
foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < col; i++)
{
if (dr[i].ToString().IndexOf(",") > 0)
{
dr[i] = "\"" + dr[i].ToString() + "\"";
}
}
}
return dt;
}
This should work: