zoukankan      html  css  js  c++  java
  • c#操作SQLIte

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SQLite;
    using System.Configuration;
    using System.Collections;
    using System.Data;
    using System.IO;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using System.Windows;
    using System.Windows.Controls;
    
    
    
    namespace Dell{
        public class Ops
        {
            public static string dbPath = "Data Source =" + Environment.CurrentDirectory + "/test.db";
            private SQLiteCommand command = new SQLiteCommand();
            private SQLiteConnection connection = null;
    
            public Ops() { }
           //重载构造函数
            public  Ops(string dbPath)
            {
                initCon(dbPath);
                Boolean b = judgeConn();
                if( b == false)
                {
                    MessageBox.Show("数据库开启失败!");
                }
            }
    
            //建立connection ,并返回链接     
            public static SQLiteConnection buildConn()
            {
                SQLiteConnection conn = new SQLiteConnection(dbPath);//创建数据库实例,指定文件位置
                conn.Open();//打开数据库,若文件不存在会自动创建
                return conn;
            }
            //建立connection,不打开
            public  void initCon(string dbPath)
            {
                connection = new SQLiteConnection(dbPath);
            }
            //判断连接状态
            private Boolean judgeConn()
            {
                Boolean isOpen = true;
                if (connection.State != ConnectionState.Open)
                {
                    try
                    {
                        //initCon(dbPath);
                        connection.Open();
    
                    }catch(Exception){
                        isOpen = false;
                    }
                }
                return isOpen;            
            }
         
         
        }
    
    }
  • 相关阅读:
    JS调试debug
    避免使用 JS 特性 with(obj){}
    bit Byte KB MB GB TB 单位换算
    C语言中连接器介绍
    [bzoj3600]没有人的算术
    [bzoj4373]算术天才⑨与等差数列
    [bzoj4151][AMPPZ2014]The Cave
    [bzoj4906][BeiJing2017]喷式水战改
    [bzoj4908][BeiJing2017]开车
    [Codeforces Round#417 Div.2]
  • 原文地址:https://www.cnblogs.com/yueyanglou/p/4317779.html
Copyright © 2011-2022 走看看