【问题标题】:Format of the initialization string does not conform to specification starting at index 121初始化字符串的格式不符合从索引 121 开始的规范
【发布时间】:2016-11-09 15:03:34
【问题描述】:

单击此按钮时,它应该将 excel 文件的内容加载到 dataGrid 中,但会收到本文标题中提到的错误。到底做错了什么?

 private void button7_Click_2(object sender, EventArgs e)
    {


        string path = "C:\\Users\\jdavis\\Downloads\\Pharmacies\\CrossReferencing v3\\CrossReferencing\\\bin\\Debug\\cross_check.xls";
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + path + ";Extended Properties=' Excel 8.0;HDR=Yes;IMEX=1;';");
        OleDbCommand command = new OleDbCommand
        (
            "SELECT"+"FROM [cross_check]",con

        );
        DataSet cross = new DataSet();
        OleDbDataAdapter adapter = new OleDbDataAdapter(command);
        adapter.Fill(cross);
        dataGridView2.DataSource = cross.Tables[0];



    }
}

【问题讨论】:

标签: c# excel winforms


【解决方案1】:

如下所示更新值,这将修复 ISAM 和格式问题。

string path = " \"C:\\Users\\jdavis\\Downloads\\Pharmacies\\CrossReferencing v3\\CrossReferencing\\bin\\Debug\\cross_check.xls\" ";
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties= Excel 8.0;IMEX=1;");

【讨论】:

    猜你喜欢
    • 2012-01-04
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多