c#, oledb connection string issue

2019-07-16 19:03发布

问题:

I'm using .net4.0 and c# language. In my code i have a connection string

oleConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;
                   Data Source = " + filepath + ";
           Extended Propertie s= \"Excel 12.0;HDR=yes\"";

and it work well. But when i change a connection string like this:

oleConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;
                   Data Source =" + filepath + "; 
           Extended Properties =\"Excel 12.0;HDR=no\"";

(I change HDR parameter for "no") I got error: No value given for one or more required parameters. error from "Microsoft Office Access Database Engine".

回答1:

If your referencing a column using say [A1] then this will fail. With HDR=No the columns are referenced as F1, F2 etc.



回答2:

OleDb Connection HDR Default is YES ans there is no option for that.

Check:

Connection strings for Access 2007

Regards



回答3:

There is no HDR=no....

The default behavioour is no headers. So just leave out the HDR part completely - that will also mean no headers.

More info: http://msdn.microsoft.com/en-us/library/ms254500.aspx