Reputation: 27
I'm trying to connect to an excel sheet (Book1.xlsx) on a network (ip=192.168.1.2). The excel sheet is my database. I know I can use access and other database, but I want to try using excel...is there a connection string that i could use in this case.
The previous connection string I was using when the database was on my machine was:
cn = new OleDbConnection(@"provider=microsoft.ace.oledb.12.0;data source=C:\Users\Michael\Desktop\Excel Prac\Book1.xlsx;extended properties=excel 12.0;");
Upvotes: 2
Views: 274
Reputation: 13484
You can use this connection string to use the Office 2007 OLEDB driver (ACE 12.0) to connect to older 97-2003 Excel workbooks.
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\computername\myOldExcelFile.xls;
Extended Properties="Excel 8.0;HDR=YES";
"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite.
Upvotes: 0
Reputation: 149325
Try this (Untested)
cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=\\192.168.1.2\<SomeFolder>\Book1.xlsx;
extended properties=excel 12.0;");
Or if you know the name of that pc then
cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=\\<NameOfPC>\<SomeFolder>\Book1.xlsx;
extended properties=excel 12.0;");
Upvotes: 2