Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Record set versus data adapter
Message
From
22/02/2005 04:01:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP
Miscellaneous
Thread ID:
00989022
Message ID:
00989151
Views:
31
>What could be wrong with the following? It works in VFP and in VB, but does not work in VB.NET.
>
>
>....
>cnnExcel = CreateObject("adodb.Connection")
>cnnExcel.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _
>        '              Excelfile + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1';")
>
>....
>' Open recordsets
>Dim rstExcel As ADODB.Recordset
>rstExcel = New ADODB.Recordset
>        With rstExcel
>            .ActiveConnection = cnnExcel
>            .CursorLocation = ADODB.CursorLocationEnum.adUseClient
>            .CursorType = ADODB.CursorTypeEnum.adOpenStatic
>            .LockType = ADODB.LockTypeEnum.adLockReadOnly
>
>* the line below gives an error
>            .Source = "SELECT * from [Matched$]"
>....
>
>
>
>However DataAdapter works:
>
>.....
>Dim DSExcel As System.Data.DataSet
>Dim ExcelAdapter As System.Data.OleDb.OleDbDataAdapter
>Dim cnnExcel As System.Data.OleDb.OleDbConnection
>
>        cnnExcel = New System.Data.OleDb.OleDbConnection( _
>             "provider=Microsoft.Jet.OLEDB.4.0; " & _
>            "data source=" & Excelfile & "; " & _
>            "Extended Properties='Excel 8.0;HDR=YES;IMEX=1';")
>
>        'Select the data from Sheet Matched of the workbook.
>        ExcelAdapter = New System.Data.OleDb.OleDbDataAdapter( _
>             "SELECT * from [Matched$]", cnnExcel)
>
>        DSExcel = New System.Data.DataSet
>        ExcelAdapter.Fill(DSExcel)
>.....
>
>
>ANy ideas?

Yuri,
Both versions are working for me:
			string strSQL = "select * from [customer$]";
			string strCon = @"Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=c:\temp\customer.xls;
  Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";

//			OleDbConnection con = new OleDbConnection(strCon);
//			OleDbDataAdapter da = new OleDbDataAdapter(strSQL, con);

			OleDbDataAdapter da = new OleDbDataAdapter(strSQL, strCon);
			DataSet ds = new DataSet();
			da.Fill(ds);
			foreach(DataRow dr in ds.Tables[0].Rows)
			{
				Console.WriteLine( "{0} {1}",dr["cust_id"], dr["contact"] );
			}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform