R
Rick van Lieshout
Hi all,
I'm trying to use the sql engine SQLite within my Visual C# project. I
downloaded the mono version of the .NET framework so I could use
Mono.Data.SqliteClient.dll , however I can't seem to be able to use the
IDataReader object. Any suggestions ?
Complete work directory:
http://home.wanadoo.nl/hgvl/Copy of SqliteTest.zip
This is my code:
-----------------------------
using System;
using System.Data;
using Mono.Data.SqliteClient;
namespace SqliteTest
{
/// <summary>
/// Summary description for SqliteTestApp.
/// </summary>
class SqliteTestApp
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string connectionString = "URI=file:SqliteTest.db";
IDbConnection dbcon;
dbcon = new SqliteConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd;
dbcmd = dbcon.CreateCommand();
dbcmd.Connection = dbcon;
string sql = "CREATE TABLE test (nummer int)";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
sql = "INSERT INTO test VALUES (12)";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
sql = "SELECT nummer FROM test";
dbcmd.CommandText = sql;
IDataReader reader;
reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int nummer = reader.GetInt32(0);
Console.WriteLine(nummer);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
}
Thanks in advance,
Rick van Lieshout
I'm trying to use the sql engine SQLite within my Visual C# project. I
downloaded the mono version of the .NET framework so I could use
Mono.Data.SqliteClient.dll , however I can't seem to be able to use the
IDataReader object. Any suggestions ?
Complete work directory:
http://home.wanadoo.nl/hgvl/Copy of SqliteTest.zip
This is my code:
-----------------------------
using System;
using System.Data;
using Mono.Data.SqliteClient;
namespace SqliteTest
{
/// <summary>
/// Summary description for SqliteTestApp.
/// </summary>
class SqliteTestApp
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string connectionString = "URI=file:SqliteTest.db";
IDbConnection dbcon;
dbcon = new SqliteConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd;
dbcmd = dbcon.CreateCommand();
dbcmd.Connection = dbcon;
string sql = "CREATE TABLE test (nummer int)";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
sql = "INSERT INTO test VALUES (12)";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
sql = "SELECT nummer FROM test";
dbcmd.CommandText = sql;
IDataReader reader;
reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int nummer = reader.GetInt32(0);
Console.WriteLine(nummer);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
}
Thanks in advance,
Rick van Lieshout