【问题标题】:Column only checks the first item. Access database列只检查第一项。访问数据库
【发布时间】:2016-04-28 02:33:41
【问题描述】:

我得到了这个 Windows 表单,它检查文本框中用户数字的用户名是否有效。但只检查列上的第一项。示例:如果我输入“john”,他会检查这是真的,因为 john 是第一个 列上的字符串,但如果我输入同一数据库中列上的第二个字符串“Stella”,程序将返回 false。

I have to upload the img because i got problems when i tried to post the code.

【问题讨论】:

  • 据我所知,您甚至没有尝试检查其他行。您需要遍历它们,直到Read() 返回false。你可以发布代码就好了。请记住单击{} 按钮进行格式化。

标签: c# database windows forms ms-access


【解决方案1】:

这是因为您没有循环遍历结果集。您需要将所有记录一一读取并实现每条记录的逻辑。

做这样的事情:

        if (usrname.HasRows)
        {
            while (usrname.Read())
            {
                 if (usrname.GetString(0) == userdigtext){
                     // messagebox here for success
                 }
                 else {
                     // messagebox here for failure
                 }
            }
        }

【讨论】:

  • 别担心,伙计。也不要忘记关闭阅读器... usrname.Close();
猜你喜欢
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-13
  • 2017-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多