in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Help - need example for select

Last post 05-26-2007 7:36 AM by Robert Simpson. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-22-2007 1:35 PM

    Help - need example for select

    Admittedly I am net to System.Data.SqLite
    I have spent 4 or more hours looking and not able to find.

    I have created a database with the 1 table I need  at the moment
    have sorta figured out how to insert data into a table
    but the select has me stumped.
    Writing the select is fine, I am familiar with SQL syntax, its what do do after the select.
    How do I loop through the returned records and display them in a list box or any where, its the retrieving them and looping through them I have yet to figure out. Actually I believ my Select is working hust don't know what to do with it after that.

    Any help is appreciated. I am using C# in VS 2005

    Thanks
    Elbert Dee Walston
  • 05-26-2007 1:11 AM In reply to

    Re: Help - need example for select

    you may search about the SQLDataReader Class, of course you should replace all occurence of SQL to SQLite prefixes
  • 05-26-2007 7:36 AM In reply to

    Re: Help - need example for select

    using (SQLiteConnection cnn = new SQLiteConnection("Data Source=mydatabase.db"))
    using (SQLiteCommand cmd = cnn.CreateCommand())
    {
      cnn.Open();
    
      // Create a new table
      cmd.CommandText = "CREATE TABLE FOO ([ID] INTEGER PRIMARY KEY, [MyValue] NVARCHAR(256)";
      cmd.ExecuteNonQuery(); // Create the table, don't expect returned data
    
      // Insert something into the table
      cmd.CommandText = "INSERT INTO FOO (MyValue) VALUES('Hello World')";
      cmd.ExecuteNonQuery();
    
      // Read the values back out
      cmd.CommandText = "SELECT * FROM FOO";
      using (SQLiteDataReader reader = cmd.ExecuteReader())
      {
        while (reader.Read())
        {
          Console.WriteLine(String.Format("ID = {0}, MyValue = {1}", reader[0], reader[1]));
        }
      }  
    }
    
Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems