zoukankan      html  css  js  c++  java
  • SQlite如何检测表是否创建

    PDA中设计数据库后,避免不了的会根据实际的需求改动功能。最害怕的是,PAD都发下去了,很多台,而工作已经开展了,数据已经有一部分了,中间要增加功能,增加表或者增加字段,怎么办?只有在更新程序的时候,判断表是否存在,不存在则临时创建,字段也类似。

      Sqlite中判断表是否存在,表名'attPointSampleEx'

                string sql = "SELECT COUNT(*)  as CNT FROM sqlite_master where type='table' and name='attPointSampleEx'";

                string sql1 = "CREATE TABLE [attPointSampleEx] ([ID] VARCHAR(50) NOT NULL UNIQUE,[PickName] VARCHAR(20)," +

                  "[SpecimenCode] VARCHAR(200), " +

                  "[PickTime] VARCHAR(19)," +

                  "[PickAddre] VARCHAR(200)," +

                  "[Lon] VARCHAR(20)," +

                  "[ZYName] VARCHAR(200), " +

                  "[ZYCode] VARCHAR(10), " +

                  "[PlantXue] VARCHAR(200), " +

                  "[HerbalPart] VARCHAR(50), " +

                  "[YongTu] VARCHAR(50), " +

                  "[SampleType] VARCHAR(2)," +

                  "[LiYong] VARCHAR(200)," +

                  "[WeiXie] VARCHAR(200)," +

                  "[Notion] VARCHAR(200));";

                //_IsCreate Bool类型,判断是否创建了表

                if (!_IsCreate)

                {

                    //读取系统表,看是否有此表的记录

                    DataTable tDT = MainDataBase.pMainDataBase.pDataBase.getDataTableFromSql(sql);

                    if (tDT != null && tDT.Rows.Count>0)

                    {

                        //判断记录

                        _IsCreate = Convert.ToInt32(tDT.Rows[0][0]) == 1;

                        if (!_IsCreate)

                        {

                            //如果没有记录,则创建表

                            _IsCreate = MainDataBase.pMainDataBase.pDataBase.ExecuteNonQuery(sql1) >= 0;

                        }

                        tDT.Dispose();

                    }

                }

    作者: cglnet
    本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    sersync 配合rsync实时同步备份
    全网实时热备inotify+rsync
    rsync定时同步配置
    NFS架构搭建详解
    visio2013密钥
    jekens介绍及服务搭建
    服务端开发新框架
    docker
    ymal
    linux部署环境配置
  • 原文地址:https://www.cnblogs.com/cglNet/p/2876542.html
Copyright © 2011-2022 走看看