sqlite 表格字段查询 和 插入

        /// 
        /// 在指定表中添加列
        /// 
        /// 表名
        /// 字段名
        /// 字段的数据类型
        /// 
        public static void AddColumn(string tablename, string columnname, string ctype)
        {
            try
            {
                // 查询字段是否存在
                string strCommond = string.Format("select count(*) from sqlite_master where name = '{0}' and sql like '%{1}%'", tablename, columnname);
                SQLiteCommand cmd = new SQLiteCommand(strCommond, dbConnection());
                int RowCount = Convert.ToInt32(cmd.ExecuteScalar());

                if (RowCount == 0)   // 当不存在时,添加字段
                {
                    cmd.CommandText = "ALTER TABLE " + tablename + " ADD COLUMN " + columnname + " " + ctype;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                _ErrorLog.Insert("ExecuteNonQuery(ALTER TABLE " + tablename + " ADD COLUMN " + columnname + " " + ctype + ")Err:" + ex);
            }
            finally
            {
                closeConn();
            }
        }

你可能感兴趣的:(sqlite)