简体   繁体   English

检查数据库中是否有空行C#

[英]Checking database for null rows C#

I have connected my codes (using visual studio C#) to my Microsoft Access database.. My application is able to add and remove user from the database. 我已经将代码(使用Visual Studio C#)连接到了Microsoft Access数据库。我的应用程序能够在数据库中添加和删除用户。 My database only allows two users (Administrator and user). 我的数据库仅允许两个用户(管理员和用户)。

Lets say that the administrator has remove the user from the database... I would the application to redirect the user to a registration page after it has detected that there is only one user in the database. 可以说,管理员已从数据库中删除了该用户...在检测到数据库中只有一个用户之后,我希望该应用程序将用户重定向到注册页面。 How can check for that using my code? 如何使用我的代码进行检查?

I have already added an SQL statement to my codes, can i add another? 我已经在代码中添加了一条SQL语句,可以添加另一个吗? how can i check for null column? 我如何检查空列?

private void Login_Load(object sender, EventArgs e)
{      
    // you can here add validation 
    //by using this sql: select count(*) from [User]


      LoginUsernameTextBox.Focus();
    }

i dont recommend using linq because it is not very flexible and working rather slow, you should learn how to write with ado in case you can face complex needs later. 我不建议使用linq,因为它不是很灵活并且工作速度很慢,因此您应该学习如何用ado编写,以防以后遇到复杂的需求。 But you already done querying part and can use the method you wrote before so it will look like this: 但是您已经完成了查询部分,可以使用之前编写的方法,因此它看起来像这样:

User[] somethin = GetAllUsers();
if(somethin.Count==1){
//now you have one user record in your database
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM