I have a window application that I developed in c# that use an mdb file to populate a dataset and show records in a listview. I made a csv export, but now I'd like to have a csv import. Can someone help me to figure it out? I tried a code, but only I can update dataset, not the access mdb file. Thank you
This is the code I've tried:
private void importDataFromCSVToolStripMenuItem_Click(object sender, EventArgs e)
{
var filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "CSV File (*.csv)|*.csv";
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " +
Path.GetDirectoryName(filePath) +
"; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter
("SELECT * FROM " + Path.GetFileName(filePath), conn);
adapter.Fill(this.dataSet1.nominativi);
conn.Close();
LoadList();
loadComboBox();
}
}
}
Comments
Post a Comment