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;            
            }
         
         
        }
    
    }
  • 相关阅读:
    typedef的用法
    重定向在网络编程中的理解
    简答的理解C语言中的各种类型函数
    栈、堆、静态存储区
    标识符起作用范围----作用域、连接类型、存储期
    main函数的argc和argv
    基本数据类型
    数组与指针
    第一章 CLR的执行模型
    Revit 二次开发 沿弧形路径创建拉伸屋顶
  • 原文地址:https://www.cnblogs.com/yueyanglou/p/4317779.html
Copyright © 2011-2022 走看看