初始化字符串的格式不符合规范指数在129年开始Format of the initialization string does not conform to specification starting at index 129

- 此内容更新于:2015-01-06
主题:

我新的c#,我相信这是一个语法错误或连接错误 这是它突出的代码错误。

原文:

I'm new to C# & I believe it is a syntax error or a connection error

Here is the code that it highlights as the error.

   private void btnLoadExcel_Click(object sender, EventArgs e)
   {
       String PathConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + ";Extended Properties='Excel    8,0;HDR=yes;    ";";
       OleDbConnection conn = new OleDbConnection(PathConn);

       OleDbDataAdapter myDataAdaptor = new OleDbDataAdapter("select 8 form [" + TBSheet.Text + "$]", conn);
       DataTable dt = new DataTable();

       myDataAdaptor.Fill(dt);

       dataGridView1.DataSource = dt;
   }
leppie的回复:应该选择8形式不是select * ?

(原文:Should select 8 form not be select * from ?)

Sam Gibson的回复:是的,它应该已经改变但accurres同样的问题

(原文:Yes it should it has been changed but the same problem accurres)

解决方案:
我建议你调试代码,看看129 -字符位置错误。 也就是说,它看起来像你混合单引号和双引号在你的“扩展属性”部分——尝试这样的: (我也“8 0”改为“8.0”,表示在connectionstrings.com上,尽管它可能是作品)
原文:

I would suggest that you debug the code and have a look at the character at position 129 - the error will be there.

That said, it does look like you're mixing a single quote and double quote in your "Extended Properties" part - try something like this:

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + ";Extended Properties="Excel 8.0;HDR=yes";";

(I've also changed "8,0" to "8.0", as indicated on connectionstrings.com, though it might be that either works)

Sam Gibson的回复:谢谢,工作

(原文:Thanks that worked)

Mike Goatly的回复:你能这个标记为答案,好吗?

(原文:Could you mark this as the answer then, please?)