473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

reading excel file

Hi,
I use
Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change the
'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank
Nov 21 '05 #1
6 1450
Im not sure of the exact syntax, but cant you do something like
[Worksheets[0]]

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
Hi,
I use
Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change the
'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank

Nov 21 '05 #2
if I specify 'worksheet' then I know the name, don't I?

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:#t**************@tk2msftngp13.phx.gbl...
Im not sure of the exact syntax, but cant you do something like
[Worksheets[0]]

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
Hi,
I use
Dim cnn As New

OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change the 'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank


Nov 21 '05 #3
My point was to address the worksheet by index rather than by name. You said
you wanted to avoid using the name right ? I mean you do have to direct the
select statment to an entity for it to work with.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function
Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news3.zwoll1.ov.home.nl...
if I specify 'worksheet' then I know the name, don't I?

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:#t**************@tk2msftngp13.phx.gbl...
Im not sure of the exact syntax, but cant you do something like
[Worksheets[0]]

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
Hi,
I use
Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change
the 'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank



Nov 21 '05 #4
I think there may be some confusion here. The Reference Terry was using is
when you're dealing with a WorkBook object in the Com interop library - that
won't work here - I'm 99% sure that the .Name property of the worksheet is
used in the derivation - not 100% sure but I'd bet $50.00 on it.

You can use the GetOleDbSchemaTable method to get a name of the tables (ie
sheets) in the workbook using it and since it comes back as a datatable,
you can use Numeric indices for iteration without knowing the names - and
from thatt you can find out what the names are. To do it with Excel
specifically -
http://support.microsoft.com/default...b;EN-US;318373

For GetOleDbSchemaTable example in general
http://www.knowdotnet.com/articles/g...hematable.html

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
Hi,
I use
Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change the
'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank

Nov 21 '05 #5
Terry: I don't think he's using the Interop library - in which case you
have an excellent point. However here I think he needs to go with the
GetOleDbSchemaTable method because a big reason for using ADO.NET to query
the sheet is to avoid Interop in the first place. It's an easy mistake to
make, have done it myself on occassion.
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ON**************@TK2MSFTNGP15.phx.gbl...
My point was to address the worksheet by index rather than by name. You said you wanted to avoid using the name right ? I mean you do have to direct the select statment to an entity for it to work with.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function
Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news3.zwoll1.ov.home.nl...
if I specify 'worksheet' then I know the name, don't I?

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:#t**************@tk2msftngp13.phx.gbl...
Im not sure of the exact syntax, but cant you do something like
[Worksheets[0]]

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
> Hi,
> I use
> Dim cnn As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
> Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
> Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
> Dim ds As New DataSet("TestExcel")
>
> da.Fill(ds)
>
> to read an excel spreadsheet. Works fine. But is it possible to

change
the
> 'select' statement so I don't have to know the sheetname?
> Thanks in advance
> Frank
>
>



Nov 21 '05 #6
GetOleDbSchemaTable works fine, thank you for the prompt reaction.
Frank

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
I think there may be some confusion here. The Reference Terry was using is when you're dealing with a WorkBook object in the Com interop library - that won't work here - I'm 99% sure that the .Name property of the worksheet is
used in the derivation - not 100% sure but I'd bet $50.00 on it.

You can use the GetOleDbSchemaTable method to get a name of the tables (ie
sheets) in the workbook using it and since it comes back as a datatable,
you can use Numeric indices for iteration without knowing the names - and
from thatt you can find out what the names are. To do it with Excel
specifically -
http://support.microsoft.com/default...b;EN-US;318373

For GetOleDbSchemaTable example in general
http://www.knowdotnet.com/articles/g...hematable.html

"Frank" <fr***@frank.com> wrote in message
news:cj**********@news1.zwoll1.ov.home.nl...
Hi,
I use
Dim cnn As New

OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\Test.xls;Extended Properties=""Excel 8.0;HDR=YES;""")
Dim da As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", cnn)
Dim ds As New DataSet("TestExcel")

da.Fill(ds)

to read an excel spreadsheet. Works fine. But is it possible to change the 'select' statement so I don't have to know the sheetname?
Thanks in advance
Frank


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Alliet | last post by:
Hello, I'm having a bit of a problem with ASP and Excel. A client has developed his own program, which calculates alot of financial stuff, in excel. I'm doing his websites and he has requested...
1
by: mail2atulmehta | last post by:
Hi, I do not know if this is right place for this, but i need some help. I have a text file, whose values are seprated by a delimiter. I want to open this file in excel, ( not import it) . I have...
1
by: Turner, GS \(Geoff\) | last post by:
> -----Original Message----- > From: siliconwafer > Posted At: 19 August 2005 15:20 > Posted To: c > Conversation: reading an excel file in C? > Subject: reading an excel file in C? > > >...
4
by: Phoebe. | last post by:
Hi, Good Day! Reading 1 excel file into a dataset is fine. How can I read multiple excel with the same data structure into 1 dataset? How can I append those data? Can someone help? Thanks in...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
3
by: Brad | last post by:
I'm having a problem reading data from an Excel file into a dataset. Can anybody give me an idea of what's happening? I've included the problematic source and the error message to the end of this...
3
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. ...
1
by: sachinkale123 | last post by:
Hi, I am reading excel file and reading values from that I am using provider As : "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Filename + ";Extended Properties=\"Excel 8.0;Hdr=No;IMEX=1\"";...
1
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.