19.5. Performing common database tasks

In this section we will show examples and usage of common database tasks using ADO.NET and EDB Connector/.NET. We will start off with learning how to open a connection to our EDB database, retrieve, display, update, delete and add new database records and then move onto more advanced examples making use of stored procedures, functions, parameterized queries, transaction and more.

When working with EDB Connector/.NET you need to import the EnterpriseDB.EDBClient namespace. The way you include varies in the case of using a ASP.NET page and when using a Windows Form, Console Application etc. The following includes are making use of C#.

  1. ASP.NET Page

    <% import namespace="EnterpriseDB.EDBClient" %>
     

  2. WinForm/Console Application

    using EnterpriseDB.EDBClient;
     

For WinForm as well as Console based applications you need to compile the respective .vb, .cs or whatever other .NET language code file you are using their respective compiler. In case of a .cs file you need to compile using the c# compiler a.k.a. "csc" and in case of a .vb file you need to use the visual basic compiler "vbc". These compilers are found in the main directory where the .NET framework is installed. The default location in case of Windows with version 1.1.4322 of the framework is: <WINDOWS_DIRECTORY>\Microsoft.NET\Framework\v1.1.4322 The same would be applicable for other .NET Framework versions.

Note:

  • For all these examples place both the EDBDataProvider.dll as well as the Mono.Security.dll in the same path as your application.

  • We are using C# as the default language for all our code samples.

  • We will be using ASP.NET pages as a convention for the examples. The same logic and code would be applicable with other .NET applications like WinForm or Console applications. The connection string for connecting to the database will be stored in a web.config file, you can save this file in an App.config if you are not making use of ASP.NET pages.

19.5.1. The web.config File

Please create, modify and save the following web.config file in the same directory as your exmaples. We will repeatedly be making use of the DB_CONN_STRING key from this configuration file for getting the connection string for our EDB server.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
	<add key="DB_CONN_STRING" value="Server=127.0.0.1;Port=5444;User Id=enterprisedb;Password=enterprisedb;Database=edb" />
</appSettings>
</configuration>