C1.AdoNet.CSV could not connect to local csv file

Posted by: levanduyet on 25 August 2023, 11:19 am EST

  • Posted 25 August 2023, 11:19 am EST

    I have created a Windows Application and try to use C1.AdoNet.Csv to connect to my local file. The code as following:

    [code]private void btnLoadData_Click(object sender, EventArgs e)

    {

    try

    {

        string csvConnectionString = @"Uri=C:\Users\DELL\Downloads\All_Movement_July2023.csv";
        using (var con = new C1CSVConnection(csvConnectionString))
        {
            con.Open();
            
            // Create Read command
            var cmd = con.CreateCommand();
            cmd.CommandText = "Select * From All_Movement_July2023.csv";
            // Execute Read command and display fetched data
            DbDataReader rdr = cmd.ExecuteReader();
            DataTable dataTable = new DataTable();
            dataTable.Load(rdr);
            if (dataTable != null)
            {
                fgData.BeginUpdate();
                fgData.DataSource = dataTable;
                fgData.EndUpdate();
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("The error is\n" + ex.Message, "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    

    }[/code]

    But the error is shown that “Open connection failed. An item with the same key has already been added.”

    C1 support pls.

    Thanks,

    Duyet Le

  • Posted 28 August 2023, 2:55 am EST

    Hello,

    C1 supporter, pls help.

    Thanks,

    Duyet Le

  • Posted 28 August 2023, 3:45 am EST

    Hello Duyet Le,

    We do not face the issue in connecting the CSV file to the Datatable using the CSV data connector. Please find the attached sample implementing the same.

    CSV_DC.zip

    Documentation Link of CSV Data Connector: https://www.grapecity.com/componentone/docs/services/online-dataconnector/csvgettingstarted.html

    Regards,

    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels