The Mono.Data.SqliteClient provides a data adapter for the Sqlite (www.sqlite.org) database, versions 2 and 3.
[Edit]
Remarks
This assemby provides a wrapper around the native Sqlite library from www.sqlite.org. The Sqlite library must be separately installed to access Sqlite databases.
SQLite has a notable oddity: table cell data does not retain what kind of data it was. Everything is stored as either a long, double, string, or blob. And in SQLite version 2, everything is stored as a string. So you need to be careful about avoiding casting values returned by SQLite without checking the type of the value returned.
See Mono.Data.SqliteClient.SqliteConnection.ConnectionString for information on the connection string format for this data provider.
C# Example |
using System;
using System.Data;
using Mono.Data.SqliteClient;
public class Test
{
public static void Main(string[] args)
{
string connectionString = "URI=file:SqliteTest.db";
IDbConnection dbcon;
dbcon = (IDbConnection) new SqliteConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT firstname, lastname " +
"FROM employee";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string FirstName = reader.GetString (0);
string LastName = reader.GetString (1);
Console.WriteLine("Name: " +
FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
} |
To build and run the example:
- Save the example to a file, such as, TestExample.cs
- Build using Mono C# compiler:
Example |
mcs TestExample.cs -r:System.Data.dll -r:Mono.Data.SqliteClient.dll |
- To run the example:
Example |
mono TestExample.exe |
[Edit]
Classes
Delegates