Does anyone here use SQLite?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Stevens

    Does anyone here use SQLite?

    I have been trying to find some working examples of working with this DB,
    but
    I can't seem to find anything at all. If I do find examples, its all
    referring to the
    command line program that comes with sqlite.

    I am trying to figure out the following using sqlite from phxsoftware.com or
    System.Data.SQL ite.

    1. How do you create a DB with a table and some fields in the table?

    2. How do you load a DB, lets say I want to open a different DB.

    3. How do you add new records into the DB?

    4. How do you delete records from the DB?

    I know each of these questions are only a few lines of code, but since I
    know
    nothing about sqlite, it is very difficult.


    Thanks in advance.


  • =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

    #2
    Re: Does anyone here use SQLite?

    Rob Stevens wrote:
    I have been trying to find some working examples of working with this DB,
    but
    I can't seem to find anything at all. If I do find examples, its all
    referring to the
    command line program that comes with sqlite.
    >
    I am trying to figure out the following using sqlite from phxsoftware.com or
    System.Data.SQL ite.
    >
    1. How do you create a DB with a table and some fields in the table?
    1. create a zero-byte file (doesn't matter how)
    SQLiteConnectio n.CreateFile can be used here if you want to use
    something provided by SQLiteConnectio n.

    2. Execute CREATE TABLE statements against the database
    Use SQLiteCommand to execute sql against the database.
    >
    2. How do you load a DB, lets say I want to open a different DB.
    Use the constructor of SQLiteConnectio n that accepts a connection string
    and use the syntax "Data Source=filename here".
    >
    3. How do you add new records into the DB?
    You execute INSERT statements against it.
    >
    4. How do you delete records from the DB?
    You execute delete statements against it.
    >
    I know each of these questions are only a few lines of code, but since I
    know
    nothing about sqlite, it is very difficult.
    Also, just for the record, always post what you have tried and what
    failed. Since you've also posted the exact same question on the SQLite
    forum, where you've also posted an example that shows that you do in
    fact know how to create the database, then my impression is that you
    already know the answers to some of your questions and thus should've
    been more specific when asking them.

    If you have more specific questions, let us know what you've tried and
    what you need help with and you'll get better answers.

    --
    Lasse Vågsæther Karlsen
    mailto:lasse@vk arlsen.no
    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

    Comment

    • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

      #3
      RE: Does anyone here use SQLite?

      I have used SQLite for a variety of different projects over the last few
      years. If you download Robert Simpson's implementation of System.Data.SQL ite
      here

      there are test cases included that show you most of the features and "how do
      I's".

      -- Peter





      "Rob Stevens" wrote:
      I have been trying to find some working examples of working with this DB,
      but
      I can't seem to find anything at all. If I do find examples, its all
      referring to the
      command line program that comes with sqlite.
      >
      I am trying to figure out the following using sqlite from phxsoftware.com or
      System.Data.SQL ite.
      >
      1. How do you create a DB with a table and some fields in the table?
      >
      2. How do you load a DB, lets say I want to open a different DB.
      >
      3. How do you add new records into the DB?
      >
      4. How do you delete records from the DB?
      >
      I know each of these questions are only a few lines of code, but since I
      know
      nothing about sqlite, it is very difficult.
      >
      >
      Thanks in advance.
      >
      >
      >

      Comment

      • Rob Stevens

        #4
        Re: Does anyone here use SQLite?

        Also, just for the record, always post what you have tried and what
        failed. Since you've also posted the exact same question on the SQLite
        forum, where you've also posted an example that shows that you do in
        The reason I posted the same exact question is because as I stated in the
        forum, I know nothing about SQL or SQLITE. I have been messing
        around with this for a few days. It is very surprising to me that there are
        almost none existent examples out there on using sqlite.

        Whenever I do find examples its based on the command line program that
        comes with sqlite source code. There are no examples for someone now
        starting out. I am not trying to get fancy with this program, I just want
        to
        know how to do the basics. I have been reading and searching for days,
        and as you can see I have come up with nothing.

        So saying do a select statement against the database is really not doing
        anything for me at all.


        Appreciate your help though.


        Comment

        • Rob Stevens

          #5
          Re: Does anyone here use SQLite?

          >I have used SQLite for a variety of different projects over the last few
          years. If you download Robert Simpson's implementation of
          System.Data.SQL ite
          here

          there are test cases included that show you most of the features and "how
          do
          I's".

          Hi Peter,

          Actually there is not a lot of the basic examples for someone now starting
          out
          with the product. It seems the more responses in there are geared toward
          the
          more difficult things. I noticed that someone asked for a sample program on
          how to do the basics back in 2006. The author said when he has time, so
          that
          may never be possible. Because I know he has a lot to do with the forum
          plus
          everything else.

          I am looking for the same too. I just want a sample program that shows how
          to
          do all the basic stuff.


          Comment

          • Eps

            #6
            Re: Does anyone here use SQLite?

            >System.Data.SQ LiteThe above is fully ADO.Net compliant, the reason your not seeing
            examples specifically for SQLite.Net is because when using a database
            from c# using ADO.Net there is virtualy no difference in the code.

            So what you want is to look into ADO.Net, be prepared to do some
            reading, or jsut do what I did which was start playing around with it.

            There is a "End to End" example of how to use SQLite, this is taken from
            the HowTo forum on their site.




            You use SQLite.NET like any other ADO.NET provider. Here's an end to
            end example:


            using System;

            using System.Data;

            using System.Data.Com mon;

            using System.Data.SQL ite;

            namespace test

            {

            class Program

            {

            static void Main(string[] args)

            {

            // Create a connection and a command

            using (DbConnection cnn = new SQLiteConnectio n("Data Source=test.db3 "))

            using (DbCommand cmd = cnn.CreateComma nd())

            {

            // Open the connection. If the database doesn't exist,

            // it will be created automatically

            cnn.Open();

            // Create a table in the database

            cmd.CommandText = "CREATE TABLE FOO (ID INTEGER PRIMARY KEY, MYVALUE
            VARCHAR(50))";

            cmd.ExecuteNonQ uery();



            // Create a parameterized insert command

            cmd.CommandText = "INSERT INTO FOO (MYVALUE) VALUES(?)";

            cmd.Parameters. Add(cmd.CreateP arameter());



            // Insert 10 rows into the database

            for (int n = 0; n < 10; n++)

            {

            cmd.Parameters[0].Value = "Value " + n.ToString();

            cmd.ExecuteNonQ uery();

            }

            // Now read them back

            cmd.CommandText = "SELECT * FROM FOO";

            using (DbDataReader reader = cmd.ExecuteRead er())

            {

            while (reader.Read())

            {

            Console.WriteLi ne(String.Forma t("ID = {0}, MYVALUE = {1}", reader[0],
            reader[1]));

            }

            }

            }

            Console.ReadKey ();

            }

            }

            }



            --
            Eps

            Comment

            • Rob Stevens

              #7
              Re: Does anyone here use SQLite?

              The above is fully ADO.Net compliant, the reason your not seeing examples
              specifically for SQLite.Net is because when using a database from c# using
              ADO.Net there is virtualy no difference in the code.
              >
              So what you want is to look into ADO.Net, be prepared to do some reading,
              or jsut do what I did which was start playing around with it.
              Wow, that exaplains a lot. Thanks a lot, I will definitely start doing
              the research now.


              Rob


              Comment

              Working...