源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#简单查询SQLite数据库是否存在数据的方法

  • 时间:2022-01-13 11:52 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#简单查询SQLite数据库是否存在数据的方法
本文实例讲述了C#简单查询SQLite数据库是否存在数据的方法。分享给大家供大家参考,具体如下:
//sqlite数据库驱动组件
using System.Data.SQLite;
//插入数据库函数
  int SQLquery(string sql)
  {
   try
   {
    //打开数据库
    SQLiteConnection conn = new SQLiteConnection();
    SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
    connstr.DataSource = "my.db";
    conn.ConnectionString = connstr.ToString();
    conn.Open();
    //执行SQL语句
    SQLiteCommand cmd = new SQLiteCommand();
    cmd.CommandText = sql;
    cmd.Connection = conn;
    SQLiteDataReader reader=cmd.ExecuteReader();
    int result=0;
    while (reader.Read())
    {
     result=1;
    }
    //关闭所有连接
    connstr.Clear();
    conn.Close();
    return result;
   }
   catch (Exception ex)
   {
        //
   }
   return 0;
}

更多关于C#相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/227.htm]C#程序设计之线程使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/805.htm]C#操作Excel技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/266.htm]C#中XML文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/165.htm]C#常见控件用法教程[/url]》、《[url=http://www.1sucai.cn/Special/125.htm]WinForm控件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/116.htm]C#数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/265.htm]C#数组操作技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/478.htm]C#面向对象程序设计入门教程[/url]》 希望本文所述对大家C#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部