Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 29-Nov-10 21:22pm
v2
Comments
Sudheer Kumar K 30-Nov-10 4:09am    
string Connectionstring = string.Format
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + Path.GetDirectoryName(filename) + "\";Extended Properties=text;HDR=No;FMT=Delimited(';');"); Can you try this. adding ; in single quotes.

1 solution

Hi,

Please follow steps:

1. Open .CSV file with programatically
2. Follow one standard (either you can set delimiter by ; or ,) and modify file accordingly
3. Save .CSV file (with only one delimiter)
4. Load in DataSet



Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
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