标签: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