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);
Anandu G NathPosted Dec 27, 2023, 8:55 AM
csv+= row[column.ColumnName].ToString().Replace(",", "^").Replace(".","|");
Meghana MPosted Mar 21, 2023, 5:08 PM
Excepted output format: this opened in notepad
column name:column1^column2^column3
row value:read^abc^bcd^efg|hij
in the above output( ', 'should replace with '^ ')and (bullet point symbol should replace with '| ')
Raj BhattPosted Mar 21, 2023, 6:51 AM
Naimish MakwanaPosted Mar 20, 2023, 3:29 PM
Try below:
Thanks
Sachin SinghPosted Mar 20, 2023, 1:49 PM
i guess this