I want to replace , with a "," in my .csv string.
For Example:
Change this
1,S0000093,GNL-000099,Aarpee Hygiene Pvt Ltd,H0010AW0101,G1150505010,G1150504070406,14,GNL-005111,,35637153767
to this
1,"S0000093","GNL-000099","Aarpee Hygiene Pvt Ltd","H0010AW010","G1150505010","G1150504070406","14","GNL-005111","","35637153767"
I have been trying the line.Replace("\"","\"\"")+"\""; but it get anything working properly.
Any help would be appreciated....Thanks in Advance...
my code
private void ExportToCsv(string fileOut)
{
string text = ",";
string text2 = "Data Source=" +
(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) +
"\\freedom.sdf;Persist Security Info=False";
SqlCeConnection sqlCeConnection = new SqlCeConnection(text2);
sqlCeConnection.Open();
string text3 = "select * from Test";
SqlCeCommand sqlCeCommand = new SqlCeCommand(text3, sqlCeConnection);
SqlCeDataReader dr = sqlCeCommand.ExecuteReader();
DataTable schemaTable = dr.GetSchemaTable();
StreamWriter streamWriter = new StreamWriter(fileOut, false);
streamWriter.WriteLine(string.Format("Sr.No,Sales Order No,Shipment No,Cust. Name,Item,Bundle No.,Roll No.,Qty,Trans Id,Validated By,Record Id", new object[0]));
while (dr.Read())
{
string text4 = "";
for (int i = 0; i < dr.FieldCount; i++)
{
object obj = dr.GetValue(i);
if (obj != null)
{
text4+= obj.ToString();
}
else
{
text4 = (text4 ?? "");
}
if (i < dr.FieldCount - 1)
{
text4 += "\"" + text.Replace("\"", "\"\"") + "\"";
}
}
streamWriter.WriteLine(text4);
}
streamWriter.Close();
sqlCeConnection.Close();
}