Advertisement
Guest User

agro

a guest
Apr 28th, 2008
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. // using mono-1.9-gtksharp-2.10.4-win32-4.exe
  2. // compile with:
  3. // gmcs -reference:System.Data.dll,Mono.Data.Sqlite.dll filename.cs
  4. // put sqlite3.dll in c:\windows\system
  5.  
  6. using System;
  7. using System.Data;
  8. using Mono.Data.Sqlite; // using Mono.Data.SqliteClient; // the olde way
  9.  
  10. class Test
  11. {
  12.    static void Main()
  13.    {
  14.       SqliteConnection conn = null;
  15.       try
  16.       {
  17. @@         conn = new SqliteConnection("Data Source=file:supernew.db");
  18.          conn.Open();
  19.  
  20.          SqliteCommand cmd = conn.CreateCommand();
  21.          
  22.      cmd.CommandText = "CREATE TABLE foo(firstname varchar(50), lastname varchar(50))";
  23.      cmd.ExecuteNonQuery();
  24.          
  25.      cmd.CommandText = "INSERT INTO foo VALUES('Hello', 'World')";
  26.      cmd.ExecuteNonQuery();
  27.          
  28.      string sqlQuery =
  29.           "SELECT firstname, lastname " +
  30.           "FROM foo";
  31.       cmd.CommandText = sqlQuery;
  32.          
  33.           IDataReader reader = cmd.ExecuteReader();
  34.           while(reader.Read()) {
  35.             string FirstName = reader.GetString (0);
  36.             string LastName = reader.GetString (1);
  37.             Console.WriteLine("Name: " +
  38.                 FirstName + " " + LastName);
  39.           }
  40.           reader.Close();
  41.       }
  42.       finally
  43.       {
  44.          if(conn != null)
  45.          {
  46.             conn.Close();
  47.          }
  48.       }
  49.    }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement