用(;)分隔符分隔的数据集值 [英] dataset values seprated by (;) delimiter

查看:87
本文介绍了用(;)分隔符分隔的数据集值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发者
请解决我求你的问题.
我有一个要加载到数据集中的csv文件,然后在datagridveiw中将其可视化,我的csv文件值用分隔符(;)分隔,默认情况下,数据集加载一个逗号(,),但是当我在oledb中使用定界符时,它不能作品.我认为我的代码中有问题,请解决.
请阅读

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(;);");


请更正此代码.
再说一遍,我的csv文件值以(;)格式分隔.不带逗号.

[edit]已校正格式的代码块-OriginalGriff [/edit]


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]

推荐答案



请按照以下步骤操作:

1.以编程方式打开.CSV文件
2.遵循一种标准(您可以通过;或,设置分隔符)并相应地修改文件
3.保存.CSV文件(只有一个定界符)
4.加载数据集



如有任何疑问,请让我知道.

请提供"投票":thumbsup:如果有帮助,请提供"接受答案",如果这是正确的答案.:rose:

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


这篇关于用(;)分隔符分隔的数据集值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆