locked
got error when i try inserting to sqlite RRS feed

  • Question

  • hi

    i work with sqlite and C# using  SQLite.NET.dll

    i make my table like this:

    string Connect;
            SQLiteConnection cn;
            SQLiteCommand cmd;
            string SQL;
             Connect = @"Data Source=c:\mydb.db;Version=3;New=True;";
           

     using (cn = new SQLiteConnection(Connect))
               {
                   using (cmd = cn.CreateCommand())
                   {
                       SQL = "CREATE TABLE  MEN(A VARCHAR(20),B VARCHAR(20),C VARCHAR(20),D VARCHAR(20));";
                       cmd.CommandText = SQL;
                       cmd.CommandType = CommandType.Text;
                       cn.Open();
                       cmd.ExecuteNonQuery();
                       cn.Close();
                   }
               }

    i try to insert like this:

     using (cn = new SQLiteConnection(Connect))
                {
                    using (cmd = cn.CreateCommand())
                    {
                        SQL = "insert into MEN(A,B,C,D) values  ('1','2','3','4')";
                        cmd.CommandText = SQL;
                        cmd.CommandType = CommandType.Text;
                        cn.Open();
                        cmd.ExecuteNonQuery();
                        cn.Close();
                    }
                }

    and i got this error:         no such table: MEN

    why ???


    • Edited by E_gold Thursday, July 5, 2012 9:20 PM
    Thursday, July 5, 2012 9:17 PM

Answers

  • Hi E_gold,

    Welcome here.

    Based on your code, maybe you have not initialized your SQL table.

    Here I give you some links about the similar issue:

    1. This application uses SQLite database to store id and description value pairs in a single table – mains and can display the contents of this table in a grid with added functionalities of adding/deleting and modifying records to and from the table:

    http://www.codeproject.com/Articles/22165/Using-SQLite-in-your-C-Application  

    2. This one is a simple GUI for creating a new SQLite database and opening an existing SQLite database. It can also create, delete and update tables in the database:

    http://www.codeproject.com/Articles/17966/SQLite-GUI

    I hope my suggestions will help.

    Regards,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us


    Monday, July 9, 2012 6:16 AM