Click here to Skip to main content
15,884,064 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my c# application i have to load a csv file to DataGridView and in my csv file have single quotes in person ID( ' ) how to remove single quotes from datagridview ('), can anyone help me please?

What I have tried:

C#
String name = "exx";
           String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                           "C:\\fingerprint\\exx.csv" +
                           ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";


           OleDbConnection con = new OleDbConnection(constr);
           OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
           con.Open();

           OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
           data = new DataTable();
           sda.Fill(data);
           dataGridView1.DataSource = data;

           ds = new DataSet();
           OleDbConnection conn = new OleDbConnection(constr);
           OleDbCommand oconnn = new OleDbCommand("Select * From [" + name + "$]", conn);

           OleDbDataAdapter sdaa = new OleDbDataAdapter(oconnn);
           sda.Fill(ds);
Posted
Updated 15-Nov-22 1:15am
v2
Comments
PIEBALDconsult 15-Nov-22 7:18am    
Is this an export from an Excel file? Which is forcing the digits to be text values?

1 solution

You would have to process the data and remove it manually from the DataTable once it was filled: either that or list the columns you want to select, and use Access's RIGHT function to remove it before it reaches the DT: String functions and how to use them - Microsoft Support[^]

Me? I wouldn't use OleDb, Access, or Excel to load CSV data anyway: A Fast CSV Reader[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900