[c#]自学c#,完成仓库管理系统笔记二————数据库连接

在登录界面实现了用户名密码检查,为空时有提示

private void Button1_Click(object sender, EventArgs e)
        {
            string id = textBox1.Text.Trim().ToString();
            string pw = textBox2.Text.Trim().ToString();
            if (id == null || id.Length == 0 || pw == null || pw.Length == 0) {
                MessageBox.Show("用户名或密码不能为空!");
                return;
            }
            string connectionstring = "Data Source = D:\\sqlite\\db823.db";
            SQLiteConnection connection = new SQLiteConnection(connectionstring);
            connection.Open();
            string sql = "select * from password where id = \"" + id + "\"";
            SQLiteDataAdapter da = new SQLiteDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            if (da != null) {
                da.Fill(ds);

                DataTable dt = ds.Tables[0];
                if (dt == null || dt.Rows == null || dt.Rows.Count == 0 || dt.Rows[0][1] == null || !dt.Rows[0][1].Equals(pw))
                {
                    MessageBox.Show("密码不匹配,请重试");
                    return;
                }
                else
                {
                    MessageBox.Show("密码匹配");
                    Form2 form2 = new Form2();
                    form2.Show();
                    this.Hide();
                }
            }
        }

todo:
1、封装数据库相关操作类
2、数据结构SQLiteDataAdapter、DataSet、DataTable具体API都不太了解(这几个==null判断的我很无语)

下一步:
搜索页面多条显示搜索结果

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值