Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // using mono-1.9-gtksharp-2.10.4-win32-4.exe
- // compile with:
- // gmcs -reference:System.Data.dll,Mono.Data.Sqlite.dll filename.cs
- // put sqlite3.dll in c:\windows\system
- using System;
- using System.Data;
- using Mono.Data.Sqlite; // using Mono.Data.SqliteClient; // the olde way
- class Test
- {
- static void Main()
- {
- SqliteConnection conn = null;
- try
- {
- @@ conn = new SqliteConnection("Data Source=file:supernew.db");
- conn.Open();
- SqliteCommand cmd = conn.CreateCommand();
- cmd.CommandText = "CREATE TABLE foo(firstname varchar(50), lastname varchar(50))";
- cmd.ExecuteNonQuery();
- cmd.CommandText = "INSERT INTO foo VALUES('Hello', 'World')";
- cmd.ExecuteNonQuery();
- string sqlQuery =
- "SELECT firstname, lastname " +
- "FROM foo";
- cmd.CommandText = sqlQuery;
- IDataReader reader = cmd.ExecuteReader();
- while(reader.Read()) {
- string FirstName = reader.GetString (0);
- string LastName = reader.GetString (1);
- Console.WriteLine("Name: " +
- FirstName + " " + LastName);
- }
- reader.Close();
- }
- finally
- {
- if(conn != null)
- {
- conn.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement