C#操作数据库、打字程序,GridView访问数据库、程序打包本地sqlite数据库文件

访问数据库的类

class MyMeans  //访问数据库的类--类包含了程序使用的数据和方法声明。类一般包含多个方法。方法定义了类的行为。
    {
   
        public static int id = 0;
        public static string Login_ID = "";  //全局变量
        public static string Login_Name = "";
        public static string Mean_SQL = "", Mean_Table = "", Mean_Field = "";
        public static SQLiteConnection My_con;
        //定义一个类型的静态公共变量,用于判断数据库是否连接成功
        public static string M_str_sqlcon = @"Data Source=sypfexam.db;Version=3";
        public static int Login_n = 0;//存储职工基本信息表中的SQL语句
        public static string AllSql = "SELECT * from  type";
        public static int examid = 0;//打字题
        public static int chuanpiaoid = 0;//传票录入
        public static int kaoshiorsuiji = 0;//随机练习是1正计时,考试是2倒计时
        Form3 frm3=new Form3();
        Form6 frm6 = new Form6();
        public static SQLiteConnection getcon()
        {
    
            My_con = new SQLiteConnection(M_str_sqlcon);
            My_con.Open();
            return My_con;
        }
        public void con_close()  //主要对数据库操作后,通过该方法判断是否与数据库连接,如果连接则关闭数据库连接
        {
   
            if (My_con.State == ConnectionState.Open)
            {
    
            My_con.Close();  //关闭数据库的连接
            My_con.Dispose();  //释放My_con变量的所有空间
            }
        }

        public SQLiteDataReader getcom(string SQLstr)  //主要SQLiteDataReader对象已只读方式读取数据库信息,并以对象进行返回
        {
    
        getcon();//打开数据库连接
        SQLiteCommand My_com=My_con.CreateCommand();
        My_com.CommandText=SQLstr; //获取指定的SQL语句
        SQLiteDataReader My_read=My_com.ExecuteReader();//执行SQL语句,生成一个sqldatareader对象
            return My_read;
        }

        public void getsqlcom(string SQLstr)  //增删改查
        {
   
            getcon();
            SQLiteCommand SQLcom = new SQLiteCommand(SQLstr, My_con);
            SQLcom.ExecuteNonQuery();//执行SQL语句
            SQLcom.Dispose();//释放所有空间
            con_close();//关闭数据库连接
        }
        public void typeexam()
        {
   
            if (examid <= 14000) //必须在数据库范围内
            {
   
                SQLiteDataReader reader = getcom("SELECT * from type where id=" + examid);
              /*  Form3 frm3 = new Form3();*/

                while (reader.Read())
                {
   
                    frm3
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值