[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Re: Connecting to an Excel File

Paul Clement

6/24/2004 4:11:00 PM

On Wed, 23 Jun 2004 13:02:01 -0700, "Frans Vander Meiren" <Frans Vander
Meiren@discussions.microsoft.com> wrote:

¤ Hi
¤
¤ Anyone who can explain me how to load and edit an Excel-file in a DataGrid via an odbcConnection?
¤ Thanks

The following should get you started:

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book20.xls;Extended Properties=""Excel 8.0;HDR=NO"""

Dim ExcelConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
ExcelConnection.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet8$]", ExcelConnection)

Dim ds As New DataSet("Workbooks")

da.Fill(ds, "Sheet8")

DataGrid1.SetDataBinding(ds, "Sheet8")


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
2 Answers

SN

1/8/2008 7:23:00 AM

0

Hi All,

I could achieve the same thing using below help.
Now, facing another problem like the excel data with numeric or datetime
data comes in datagrid along with the same formatting applied.
So the header for numeric columns(e.g. Price/Quantity) does not show in grid.
Can anyone suggest any soln on this?

Thanks in advance.


"Frans Vander Meiren" wrote:

> Thanks a lot, Paul. I''ll try it
>
> Frans
>
> "Paul Clement" wrote:
>
> > On Wed, 23 Jun 2004 13:02:01 -0700, "Frans Vander Meiren" <Frans Vander
> > Meiren@discussions.microsoft.com> wrote:
> >
> > &#194;&#164; Hi
> > &#194;&#164;
> > &#194;&#164; Anyone who can explain me how to load and edit an Excel-file in a DataGrid via an odbcConnection?
> > &#194;&#164; Thanks
> >
> > The following should get you started:
> >
> > ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > "Data Source=e:\My Documents\Book20.xls;Extended Properties=""Excel 8.0;HDR=NO"""
> >
> > Dim ExcelConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
> > ExcelConnection.Open()
> >
> > Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet8$]", ExcelConnection)
> >
> > Dim ds As New DataSet("Workbooks")
> >
> > da.Fill(ds, "Sheet8")
> >
> > DataGrid1.SetDataBinding(ds, "Sheet8")
> >
> >
> > Paul ~~~ pclement@ameritech.net
> > Microsoft MVP (Visual Basic)
> >

Thuta

5/9/2008 8:58:00 AM

0

string Provider = "provider=Microsoft.Jet.OLEDB.4.0; data source=''" +
fileName + " ''; " +"Extended Properties=''Excel 8.0;HDR=YES;IMEX=1''";

You need to set the parameter IMEX = 1


"SN" wrote:

> Hi All,
>
> I could achieve the same thing using below help.
> Now, facing another problem like the excel data with numeric or datetime
> data comes in datagrid along with the same formatting applied.
> So the header for numeric columns(e.g. Price/Quantity) does not show in grid.
> Can anyone suggest any soln on this?
>
> Thanks in advance.
>
>
> "Frans Vander Meiren" wrote:
>
> > Thanks a lot, Paul. I''ll try it
> >
> > Frans
> >
> > "Paul Clement" wrote:
> >
> > > On Wed, 23 Jun 2004 13:02:01 -0700, "Frans Vander Meiren" <Frans Vander
> > > Meiren@discussions.microsoft.com> wrote:
> > >
> > > &#194;&#164; Hi
> > > &#194;&#164;
> > > &#194;&#164; Anyone who can explain me how to load and edit an Excel-file in a DataGrid via an odbcConnection?
> > > &#194;&#164; Thanks
> > >
> > > The following should get you started:
> > >
> > > ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > > "Data Source=e:\My Documents\Book20.xls;Extended Properties=""Excel 8.0;HDR=NO"""
> > >
> > > Dim ExcelConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
> > > ExcelConnection.Open()
> > >
> > > Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet8$]", ExcelConnection)
> > >
> > > Dim ds As New DataSet("Workbooks")
> > >
> > > da.Fill(ds, "Sheet8")
> > >
> > > DataGrid1.SetDataBinding(ds, "Sheet8")
> > >
> > >
> > > Paul ~~~ pclement@ameritech.net
> > > Microsoft MVP (Visual Basic)
> > >