如何使用 C# 将表值与文本框值匹配

发布于 2024-07-20 06:20:49 字数 380 浏览 4 评论 0原文

这是选择用户密码的代码,其中 id = 1 ; 我想将此值与文本框匹配。 如果该值匹配,则将打开第二个窗口窗体。 但它不起作用......

OleDbConnection con = new OleDbConnection(database2.conn);
con.Open();
OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con);
OleDbDataReader Dreader = OCom.ExecuteReader();

while (Dreader.Read())
{
  MessageBox.Show(Dreader + "");
}

This is code for select user password where id = 1 ; I want to match this value to a text box. If the value is a match then second window form will be open. But it is not working ...

OleDbConnection con = new OleDbConnection(database2.conn);
con.Open();
OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con);
OleDbDataReader Dreader = OCom.ExecuteReader();

while (Dreader.Read())
{
  MessageBox.Show(Dreader + "");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

口干舌燥 2024-07-27 06:20:49

如果我没记错的话我想你可以使用

while(Dreader.Read())
{
    if(Dreader["_password"].ToString()==txtbox.text)
    {
    objectofform.show()
    }
}

If I am not wrong I think you can use

while(Dreader.Read())
{
    if(Dreader["_password"].ToString()==txtbox.text)
    {
    objectofform.show()
    }
}
堇年纸鸢 2024-07-27 06:20:49

将您的对象包装在 using 语句中......这样它们就会在完成后关闭并处置。 返回您正在查找的字符串...如果 GetPassword() == null,则未找到,否则返回字符串。

public string GetPassword()
{

using (OleDbConnection con = new OleDbConnection(database2.conn))
{

using (OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con))
{
    con.Open();

    using (IDataReader Dreader = OCom.ExecuteReader())
    {
        if (Dreader.Read())
        {
            return Dreader.GetString(0);
        } else return null;
    }
}

}

}

Wrap your objects in using statements....so they will close and dispose when done. Return the string you are looking for... if GetPassword() == null, not found otherwise its the string returned.

public string GetPassword()
{

using (OleDbConnection con = new OleDbConnection(database2.conn))
{

using (OleDbCommand OCom = new OleDbCommand("select user_pasword from tblpasword where id = 1", con))
{
    con.Open();

    using (IDataReader Dreader = OCom.ExecuteReader())
    {
        if (Dreader.Read())
        {
            return Dreader.GetString(0);
        } else return null;
    }
}

}

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文