Net-informations.com
SiteMap  | About    

ASP.NET OLEDB Connection

The ASP.NET OleDbConnection instance takes Connection String as argument and pass the value to the Constructor statement. An instance of the ASP.NET OleDbConnection class is supported the OLEDB Data Provider .

vb.net
  Dim connectionString As String
  Dim connection As OleDbConnection
  connectionString = ConfigurationManager.ConnectionStrings("OLEDbConnection").ToString

connection = New OleDbConnection(connectionString)

C#
  string connectionString = ConfigurationManager.ConnectionStrings["OLEDbConnection"].ToString();

OleDbConnection connection = new OleDbConnection(connectionString);

When the connection is established betweenASP.NET application and the specified Data Source, SQL Commands will execute with the help of the Command Object and retrieve or manipulate data in the database. Once the Database activities is over Connection should be closed and release from the data source resources .

The Close() method in the OleDbConnection class is used to close the Database Connection. The Close method Rolls Back any pending transactions and releases the Connection from the Database connected by the OLEDB Data Provider.

Copy and paste the following content into your web.config file and provide the parameter values.

web.config

  

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
	<add name="OLEDbConnection"
		 connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=your database path\yourdatabasename.mdb;"
		 providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

The following ASP.NET program trying to establish connection to a .mdb file and display the message in Label control.

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
	</div>
	<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb





net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.