[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.odbcnet

ADO.NET and Excel 3.0 format

Benjsoft

11/28/2002 2:26:00 AM

Gud day,

Hi, i have a problem in reading Excel 3.0 format file
using ODBC.NET Data Provider (Even OleDb.Net), can anybody
in this forum help me to construct a sample ADO.NET
snippet that can load Excel 3.0 file and return a dataset?

Upgrading to 2000/XP is not my option. If it is, i have no
problem at all.

Thanks.
1 Answer

(Elan Zhou(MS))

11/28/2002 9:51:00 AM

0

Hi,

The following code tests ok on my machine against the Excel 3.0 worksheet.
(I generate the worksheet in Excel XP and save it as Excel 3.0 format for
testing.)
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Inherits System.Windows.Forms.Form
Dim objDataset1 As DataSet()
. . .
. . .
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended
Properties=""Excel 3.0;HDR=YES;"""

Dim objConn As New OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New OleDbCommand("SELECT * FROM [book1$]",
objConn)
Dim objAdapter1 As New OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Test")
DataGrid1.DataSource = objDataset1.Tables(0).DefaultView
objConn.Close()
End Sub
End Class

In addition, here is an article you can refer to:
HOW TO: Use ADO.NET to Retrieve and Modify Records in an Excel Workbook
With Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-...

Regards,
Elan Zhou
This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.got...