码迷,mamicode.com
首页 > 数据库 > 详细

VS2017 C# winform 项目使用 sqlite (二)

时间:2018-04-12 13:28:14      阅读:449      评论:0      收藏:0      [点我收藏+]

标签:value   ext   btn   登录   click   mes   cep   else   dir   

(一)连接数据库&查询数据库,(例子:用户登录窗)

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            //登录检测
            try
            {
                //连接数据库
                string dbPath = "Data Source=" + Directory.GetCurrentDirectory() + @"\data\orders.db;Version=3;Password=07762828216;";
                SQLiteConnection conn = new SQLiteConnection(dbPath);
                conn.Open();
                //查询是否有相应的数据
                string sql_select = "select count(0) from users where username = ‘" + TxbUsername.Text.Trim() + "‘ and password = ‘" + TxbPassword.Text.Trim()+"";
                SQLiteCommand cmd = new SQLiteCommand(sql_select,conn);
                SQLiteDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    string result = reader.GetValue(0).ToString();
                    if (result == "0")
                    {
                        MessageBox.Show("用户名或密码错误,请重新输入!"); 
                    }
                    else
                    {
                        MessageBox.Show("登录成功!");
                    }
                }
                reader.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
               MessageBox.Show("连接数据库失败:" + ex.Message);
            }
        }

 

VS2017 C# winform 项目使用 sqlite (二)

标签:value   ext   btn   登录   click   mes   cep   else   dir   

原文地址:https://www.cnblogs.com/nb08611033/p/8806938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!