SQLITE:接近“of”语法错误(代码1);在编译INSERT INTO MyTable时

时间:2016-05-13 08:08:26

标签: c#

我试图将我的记录添加到我的表中,但它出现了这种语法错误。

这是我的代码。 代码图片:http://i.imgur.com/lUNKFfK.png

public void CreateDatabase(string sqldb_name)
        {
            try
            {
                sqldb_message = "";
                string sqldb_location = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                string sqldb_path = Path.Combine(sqldb_location, sqldb_name);
                bool sqldb_exists = File.Exists(sqldb_path);
                if (!sqldb_exists)
                {
                    sqldb = SQLiteDatabase.OpenOrCreateDatabase(sqldb_path, null);
                    sqldb_query = "CREATE TABLE IF NOT EXISTS MyTable (_PhoneNumber INTEGER PRIMARY KEY AUTOINCREMENT, Name VARCHAR, Password VARCHAR, DateOfBirth VARCHAR);";
                    sqldb.ExecSQL(sqldb_query);
                    sqldb_message = "Database: " + sqldb_name + " created";
                }
                else
                {
                    sqldb = SQLiteDatabase.OpenDatabase(sqldb_path, null, DatabaseOpenFlags.OpenReadwrite);
                    sqldb_message = "Database: " + sqldb_name + " opened";
                }
                sqldb_available = true;
            }
            catch (SQLiteException ex)
            {
                sqldb_message = ex.Message;
            }
        }
        //Adds a new record with the given parameters
        public void AddRecord(string PhoneNumber, string Pwd, string Name, string DOB)
        {
            try
            {
                sqldb_query = "INSERT INTO MyTable (PhoneNumber, Password, Name, Date Of Birth) VALUES ('" + PhoneNumber + "','" + Pwd + "'," + Name + "," + DOB + ");";
                sqldb.ExecSQL(sqldb_query);
                sqldb_message = "Record saved";
            }

            catch (SQLiteException ex)
            {
                sqldb_message = ex.Message;
            }
        }

1 个答案:

答案 0 :(得分:1)

您的列名与插入中指定的列名不多。使用:

INSERT INTO MyTable (_PhoneNumber, Password, Name, DateOfBirth) VALUES ...

还使用参数