Hi developer
Please solve my problem I beg to you.
I have a csv file that I am load in a dataset then visualize them in datagridveiw, my csv file values are seprated by delimeter (;) and dataset by default load a comma (,) but when i am use a delimiter in oledb its cannot works. I think there is a problem in my code please solve them .
Please read them
public static DataSet GetDataset(string filename)
{
string Connectionstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + Path.GetDirectoryName(filename) +
"\";Extended Properties=text;HDR=No;FMT=Delimited(;);");
string cmdstring = string.Format(@"SELECT * FROM {0}", Path.GetFileName(filename).Trim());
DataSet dataset = new DataSet();
using (OleDbConnection olconn = new OleDbConnection(Connectionstring))
{
olconn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
dataset.Clear();
adapter.Fill(dataset, "Test");
olconn.Close();
}
return dataset;
}
public void Browse_Click(object sender, EventArgs e)
{
try
{
OpenFileDialogbox.InitialDirectory = Application.ExecutablePath.ToString();
DialogResult RESULT = this.OpenFileDialogbox.ShowDialog();
if (RESULT == DialogResult.OK)
{
string filename = OpenFileDialogbox.FileName;
Locations.Text = filename;
}
else
{
MessageBox.Show("Dear User Please select Path");
}
DataSet dataset = Form1.GetDataset(Locations.Text);
Datagidveiw1.DataSource = dataset.Tables[0].DefaultView;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Please check this code and correct them, I beg to u .
string Connectionstring = string.Format
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + Path.GetDirectoryName(filename) + "\";Extended Properties=text;HDR=No;FMT=Delimited(;);");
please correct this code code .
again I want to say ,my csv file values are seprated by(;) format. Not with comma.
[edit]Code block corrected for formatting - OriginalGriff[/edit]