ADO.NET for access.

  • Thread starter Thread starter Mr. x
  • Start date Start date
M

Mr. x

Hello,
I know that OleDB works for access.
Does ADO.NET works for access too.
I need code samples, please.

Thanks :)
 
If you mean can you access and manipulate data in a Jet database (MDB) via
ADO.NET, yes, you can, using the components in the System.Data.OleDb
namespace (OleDbConnection, OleDbDataAdapter, OleDbCommand). I did encounter
some 'issues', which I described in an earlier post in this newsgroup, but I
managed to work around them.

Here's an example that fills a DataGrid control with data from the Employees
table in the Northwind database. Note that most of this code was generated
by VS.NET - the only code I had to write was the code in the Page_Load
event.

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.DataSet11 = New WebApplication1.DataSet1
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Program
Files\Microso" & _
"ft Office\Office\Samples\Northwind.mdb"";Password=;Jet OLEDB:Engine
Type=5;Jet OL" & _
"EDB:Global Bulk
Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:Syst" & _
"em database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share
Deny None;Jet O" & _
"LEDB:New Database Password=;Jet OLEDB:Create System
Database=False;Jet OLEDB:Don" & _
"'t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;U" & _
"ser ID=Admin;Jet OLEDB:Encrypt Database=False"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "Employees", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("EmployeeID", "EmployeeID"), New
System.Data.Common.DataColumnMapping("FirstName", "FirstName"), New
System.Data.Common.DataColumnMapping("LastName", "LastName")})})
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT EmployeeID, FirstName,
LastName FROM Employees"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-IE")
CType(Me.DataSet11,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Protected WithEvents OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Protected WithEvents OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Protected WithEvents DataSet11 As WebApplication1.DataSet1

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
OleDbDataAdapter1.Fill(DataSet11)
DataGrid1.DataBind()
End If

End Sub

End Class
 
See my first question :
I asked - if there is alternative (and not not not oleDB !!!, as I have
mentioned) for accessing access database (MDB), like by ADO.NET ?
I need a sample code, please.

Thanks :)
 
The code I posted is ADO.NET code. ADO.NET connects to data sources using a
data provider. The data providers included in the .NET Framework 1.1 are SQL
Server, OLE DB, Oracle, and ODBC. The Oracle and ODBC providers were not
included in the .NET Framework 1.0, but I believe they can be downloaded
from MSDN. If you don't want to use the OLE DB provider, I expect you could
probably use the ODBC provider, but I have not tested it, and am not aware
of any reason to prefer it over OLE DB for connecting to a Jet database. For
more information and examples, see the topic 'Connecting to a data source
using ADO.NET' in the .NET Framework SDK, or try a .NET newsgroup. The SDK
can be downloaded from the following URL ...

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en
 
Back
Top