A way with DataTable =>
// Add at beginning : using System.Data.OleDb;
string sFileName = @"E:\test_csv.csv";
string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.IO.Path.GetDirectoryName(sFileName) + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"";
OleDbConnection oleConn = new OleDbConnection(sConnectionString);
string sSQLQuery = "Select * From " + System.IO.Path.GetFileName(sFileName);
OleDbCommand oleCommand = new OleDbCommand(sSQLQuery, oleConn);
OleDbDataAdapter oleAdapt = new OleDbDataAdapter(oleCommand);
DataTable dt = new DataTable();
oleAdapt.Fill(dt);
// Update cell
dt.Rows[2][4] = "2";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (DataColumn dc in dt.Columns)
{
sb.Append(dc.ColumnName);
sb.Append(",");
}
sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
foreach (DataRow r in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append(r.ItemArray[i].ToString());
sb.Append(",");
}
sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
}
System.IO.File.WriteAllText(sFileName, sb.ToString());
Tested with this .CSV :
WH_CODE,LINE_CODE,STATION_CD,KEY_NAME,KEY_VAL
HJ,1,1,check1,1
HJ,1,1,check2,1
HJ,2,1,check3,0
HJ,1,1,check4,1