Help with a OleDB connection string for excel files

Unfortunately, you can’t set ImportMixedTypes or TypeGuessRows from the connection string since those settings are defined in the registry. For the ACE OleDb driver, they’re stored at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel in the registry. So, you can simplify your connection string to: conn.ConnectionString = @”Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx;Extended Properties=””Excel 12.0 Xml;HDR=Yes;IMEX=1;”””; Once you set TypeGuessRows to 0 and … Read more

JSON.net serialize directly from oledbconnection

Firstly, you should stop serializing to an intermediate string and instead serialize directly to the HttpResponse.OutputStream, using the following simple methods: public static class JsonExtensions { public static void SerializeToStream(object value, System.Web.HttpResponse response, JsonSerializerSettings settings = null) { if (response == null) throw new ArgumentNullException(“response”); SerializeToStream(value, response.OutputStream, settings); } public static void SerializeToStream(object value, TextWriter … Read more

Parsing CSV using OleDb using C#

You should indicate only the directory name in your connection string. The file name will be used to query: var filename = @”c:\work\test.csv”; var connString = string.Format( @”Provider=Microsoft.Jet.OleDb.4.0; Data Source={0};Extended Properties=””Text;HDR=YES;FMT=Delimited”””, Path.GetDirectoryName(filename) ); using (var conn = new OleDbConnection(connString)) { conn.Open(); var query = “SELECT * FROM [” + Path.GetFileName(filename) + “]”; using (var adapter … Read more

tech