PC Review


Reply
Thread Tools Rate Thread

ADO.NET connection string for Excel

 
 
=?Utf-8?B?TW9yaQ==?=
Guest
Posts: n/a
 
      6th Dec 2005
Need a good working example of reading Excel using ADO.NET. Here is what I
have but it does not work. The problem seems to be how to escape the quotes
in the Extended properties. Any suggestions appreciated.

StringBuilder sb = new StringBuilder();
string strConn = "";
sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
sb.Append("DataSource=").Append(strFileName).Append(";").Append("Extended
Properties=");
sb.Append("\"").Append("\"").Append("Excel
8.0;").Append("HDR=Yes").Append("\"").Append("\"").Append("\"");
strConn = sb.ToString();

 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      6th Dec 2005
Hi,

As usual, you should check out this fine page:
http://www.connectionstrings.com/

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Mori" <(E-Mail Removed)> wrote in message
news:EF3F1E2B-13A9-415A-AFCA-(E-Mail Removed)...
> Need a good working example of reading Excel using ADO.NET. Here is what
> I
> have but it does not work. The problem seems to be how to escape the
> quotes
> in the Extended properties. Any suggestions appreciated.
>
> StringBuilder sb = new StringBuilder();
> string strConn = "";
> sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
> sb.Append("DataSource=").Append(strFileName).Append(";").Append("Extended
> Properties=");
> sb.Append("\"").Append("\"").Append("Excel
> 8.0;").Append("HDR=Yes").Append("\"").Append("\"").Append("\"");
> strConn = sb.ToString();
>



 
Reply With Quote
 
=?Utf-8?B?TW9yaQ==?=
Guest
Posts: n/a
 
      6th Dec 2005
This is the error I get:

Format of the initialization string does not conform to specification
starting at index 93." here is my connection string:

string strConn = "";
StringBuilder sb = new StringBuilder();
string strFileName = @"C:\FolderToWatch\xData.xls";
string qt = "\"\"";
sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
sb.Append("DataSource=").Append(strFileName).Append(";");
sb.Append("Extended Properties=").Append(qt);
sb.Append("Excel 8.0;HDR=Yes;").Append(qt);


The string looks like this when I do console.writeline:
Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\FolderToWatch\xData.xls;Extended
Properties=""Excel 8.0;HDR=Yes;""


Why is not working then?




"Miha Markic [MVP C#]" wrote:

> Hi,
>
> As usual, you should check out this fine page:
> http://www.connectionstrings.com/
>
> --
> Miha Markic [MVP C#]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> "Mori" <(E-Mail Removed)> wrote in message
> news:EF3F1E2B-13A9-415A-AFCA-(E-Mail Removed)...
> > Need a good working example of reading Excel using ADO.NET. Here is what
> > I
> > have but it does not work. The problem seems to be how to escape the
> > quotes
> > in the Extended properties. Any suggestions appreciated.
> >
> > StringBuilder sb = new StringBuilder();
> > string strConn = "";
> > sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
> > sb.Append("DataSource=").Append(strFileName).Append(";").Append("Extended
> > Properties=");
> > sb.Append("\"").Append("\"").Append("Excel
> > 8.0;").Append("HDR=Yes").Append("\"").Append("\"").Append("\"");
> > strConn = sb.ToString();
> >

>
>
>

 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      6th Dec 2005
Hi Mori,

I guess the connection string listed at www.connectionstrings.com is for use
with VB.NET (thus the double quotes).
Use single quotes instead.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Mori" <(E-Mail Removed)> wrote in message
news:B552E887-1293-4DD5-BB3F-(E-Mail Removed)...
> This is the error I get:
>
> Format of the initialization string does not conform to specification
> starting at index 93." here is my connection string:
>
> string strConn = "";
> StringBuilder sb = new StringBuilder();
> string strFileName = @"C:\FolderToWatch\xData.xls";
> string qt = "\"\"";
> sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
> sb.Append("DataSource=").Append(strFileName).Append(";");
> sb.Append("Extended Properties=").Append(qt);
> sb.Append("Excel 8.0;HDR=Yes;").Append(qt);
>
>
> The string looks like this when I do console.writeline:
> Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\FolderToWatch\xData.xls;Extended
> Properties=""Excel 8.0;HDR=Yes;""
>
>
> Why is not working then?
>
>
>
>
> "Miha Markic [MVP C#]" wrote:
>
>> Hi,
>>
>> As usual, you should check out this fine page:
>> http://www.connectionstrings.com/
>>
>> --
>> Miha Markic [MVP C#]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>> "Mori" <(E-Mail Removed)> wrote in message
>> news:EF3F1E2B-13A9-415A-AFCA-(E-Mail Removed)...
>> > Need a good working example of reading Excel using ADO.NET. Here is
>> > what
>> > I
>> > have but it does not work. The problem seems to be how to escape the
>> > quotes
>> > in the Extended properties. Any suggestions appreciated.
>> >
>> > StringBuilder sb = new StringBuilder();
>> > string strConn = "";
>> > sb.Append("Provider=Microsoft.Jet.OLEDB.4.0;");
>> > sb.Append("DataSource=").Append(strFileName).Append(";").Append("Extended
>> > Properties=");
>> > sb.Append("\"").Append("\"").Append("Excel
>> > 8.0;").Append("HDR=Yes").Append("\"").Append("\"").Append("\"");
>> > strConn = sb.ToString();
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing from Excel using a connection string? Maury Markowitz Microsoft Access Form Coding 0 18th Aug 2009 06:35 PM
ODBC connection string Excel to AS/400 hollywoodsign@gmail.com Microsoft Excel Programming 4 19th Sep 2006 09:57 PM
The Connection string to Excel ad Microsoft ADO .NET 1 8th May 2006 02:53 PM
Version of Excel in Connection String Prasun Microsoft ADO .NET 1 2nd May 2005 04:58 PM
ado connection string for excel 2002 Priyesh Microsoft Excel Programming 0 5th Jan 2004 10:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:31 AM.