Meghana M

Meghana M

  • 1.6k
  • 175
  • 23.6k

How to replace( , to ^) character and( . to |)exporting data from sql

Mar 20 2023 11:50 AM

I need to replace( , to ^)  and( . to |)charaters  while exporting data from sql  to csv .Where can i change the code for mentioned character in below code 

Code:

command.CommandText = "SpGetData";
command.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dataAdapter = new SqlDataAdapter(command.CommandText, connect);
dataAdapter.Fill(dataSet, "SpGetData");
DataTable t1 = dataSet.Tables["SpGetData"];

string csv1 = string.Empty;

foreach (DataColumn column in t1.Columns)
{
       csv1 += column.ColumnName + ',';
}
foreach (DataRow row in t1.Rows)
{
   foreach (DataColumn column in t1.Columns)
    {
        csv1 += row[column.ColumnName].ToString().Replace(",", ";") + ',';
    }
}
string filename = exportPath + "Data" ;
File.WriteAllText(filename, csv1);

 


Answers (5)