Installing - .NET Framework

DataTables and Editor are powerful libraries, but before you can use them, they need to be installed on your system! This guide walks through how to download the .NET Editor package and set it up. The end result will be the ability to run all of the Editor examples in your .NET Framework environment.

Demo package installation

This installation is a simple four step process which the documentation below will guide you though.

Download

To download the Editor .NET Framework package, open the Editor download page and select the Editor .NET Framework package. If you already have a DataTables account the download will start immediately. If you don't have a DataTables account you will be asked to create one to start a trial.

When the download completes, unzip the files and open the Visual Studio file (if you don't have Visual Studio, Microsoft publish a free community edition).

Examples SQL

With the project successfully opened in Visual Studio, we now need to load your database with the tables and data required for the Editor examples. The .NET libraries work with a number of different databases, each of which requires its own SQL. The following links contain the SQL needed for each of the supported databases:

Select the appropriate file for your database and then run the SQL contained within on your database access portal (SQL Server Management Studio, CLI, phpMyAdmin or pgAdmin3 for example). The demo SQL will create new tables and enter data into them. Note that they will overwrite any conflicting table names - installing into a new database is recommended, and also, as is good practice, ensure that you have backed up your database.

Database connection

The next step is to set up the database connection so the Editor libraries can interact with the server, reading and modified data as required. This is done through the Database class in the DataTables namespace, which is a database abstraction layer, so it can interface with any of the above database types.

In each controller a Database class instant is initialised. This class uses ADO.NET connection pooling to efficiently connect to your database, while ensuring that each Ajax request is independent of other requests:

var settings = Properties.Settings.Default;

using (var db = new Database(settings.DbType, settings.DbConnection))
{
    ...
}

A using() statement is used to ensure that the database connection is correctly closed after the controller has finished using it.

In the above code, you'll notice that two application properties are used. These are defined in the project's settings and can be reused throughout your application, referenced and managed from a singe location, should you need to change them later. To modify these properties, double click the Settings.settings file in the application Properties option (in the Solution Explorer).

There are two settings defined for the example application:

  • DbType - This defines the database type you are connecting to and can be one of:
    • azure - Microsoft Azure
    • mysql - MySQL
    • postgres - PostgreSQL
    • oracle - Oracle
    • sqlite - SQLite
    • sqlserver - SQL Server
    • sqlserverce - SQL Server CE (for local file databases)
  • DbConnection - This is the database connection string to connect to the SQL server. The exact format of the connection string depends upon the server being used, but typically it includes the server host name / address, user name and password. The Connection Strings web-site can be useful if you aren't sure of what connection string to use for your server.

Running the examples

That's all the set up that is needed to run the examples! To actually run them, now press F5 or select the Start debugging option from the Debug menu in Visual Studio.

NuGet

The Editor server-side libraries for .NET are available on NuGet for easy inclusion in your project without needing to build or locally reference the DataTables-Editor-Server.dll yourself. To install via NuGet search in Visual Studio's NuGet explorer for "DataTables-Editor-Server" and install. If you prefer to install on the command line use:

# Package manager:
Install-Package DataTables-Editor-Server

# or
# .NET CLI
dotnet add package DataTables-Editor-Server

Database connection

The Editor libraries make use of an ADO.NET connection to a database to read and write the data as required for the DataTable in question. To establish a connection use the Database class from the Editor libraries. This can be in the form of one of the following (note that the examples make use of the using statement to ensure that the connection is closed when no longer required - you could call db.Close() manually if you prefer):

A connection string. Note that the values DbType can take is defined in the list of strings above. If using this method, you may wish to store the connection string in a global configuration like the demo examples (shown above).

using (var db = new Database( String type, String connectionString))
{
    ...
}

An existing DbConnection.

using (var db = new Database( String type, DbConnection connection))
{
    ...
}

DbConnectionStringBuilder.

using (var db = new Database( String type, DbConnectionStringBuilder builder))
{
    ...
}

Next steps

With the examples running, the next step is to start experimenting with the examples and understanding how the Editor C# code operates. Beyond that, you can start to include Editor in your own applications (Web API / MVC)!