如何检查db sqlite xamarin iOS中存在的表 [英] how to check table exist in db sqlite xamarin iOS

查看:28
本文介绍了如何检查db sqlite xamarin iOS中存在的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查db数据库中表的创建位置.

How to check where table is created in db database or not.

var folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
        SQLiteConnection db = new SQLiteConnection (System.IO.Path.Combine (folder,"note.db"));
        try{
            var existTable = db.Query<TransationTable>("SELECT count(*) FROM sqlite_master WHERE type = 'Table' AND name = 'TransationTable' ");
            Console.WriteLine ("Count {0}",existTable.Count);
          if(existTable.Count == 0){
          tableview.Hidden = true;
          lbl_NotFound.Hidden = false;
        }
    else{
          tableview.Hidden = false;
          lbl_NotFound.Hidden = true;
    }

        }
        catch{
            Console.WriteLine ("Calling Excpetion!");
        }
 }

它总是给我 1.
@提前致谢.

Its always gives me of count 1.
@thanks in advance.

推荐答案

    var info = conn.GetTableInfo(tableName);
    if (!info.Any())
    {
        conn.CreateTable<T>();
    }

这篇关于如何检查db sqlite xamarin iOS中存在的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆