android sqlite CREATE TABLE IF NOT EXISTS

前端 未结 2 1431
不知归路
不知归路 2021-02-19 02:26

Having a little problem with creating new tables. When I use the CREATE TABLE command my new tables form as they should, but when I exit the activity the app crashes and I get a

2条回答
  •  时光说笑
    2021-02-19 02:42

    I use it like this:

       internal static int checkTable()
        {
            DataTable dTable = new DataTable();
            try
            {
                dbConn = new SQLiteConnection("Data Source=" + dbFileName + ";Version=3;");
                dbConn.Open();
                sqlCmd.Connection = dbConn;
    
                String makeTable = "CREATE TABLE IF NOT EXISTS responde( id INTEGER PRIMARY KEY AUTOINCREMENT, sid TEXT, ans TEXT, answe TEXT, questid TEXT, timestamp TEXT)";
    
                sqlCmd.CommandText = makeTable;
                sqlCmd.ExecuteNonQuery();
                return 1;
            }
            catch (SQLiteException) { Console.WriteLine("Error DB 100"); return 0; }
            catch (IndexOutOfRangeException) { Console.WriteLine("Error DB 101"); return 0; }
            catch (TypeInitializationException) { Console.WriteLine("Error DB 102"); return 0; }
        }
    

提交回复
热议问题