我该如何解决C#数据库的问题? [英] How can I solve this problem of C# databse?

查看:66
本文介绍了我该如何解决C#数据库的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Windows应用程序,该应用程序仅显示一个表单以输入用户名和密码.用户单击登录按钮时,数据库中必须同时显示用户名和密码文本框值,如果没有,则显示您尚未创建帐户"的消息框.
我已经在sqlserver数据库中创建了一个Login表.我已经做了很多尝试来创建它.
我在登录按钮的单击事件中编写了以下代码.

I want to create a windows application which simply displays a form to enter username and password. When user clicks the login button, both username and password textboxes value must present in the database, if not then display a messagebox that ‘you have not created your account’.
I have created a Login table in sqlserver database. I have done lot of try to create it.
I have written following code in login’s button click event.

SqlConnection conn = new SqlConnection(conString);
SqlDataAdapter da = new SqlDataAdapter("SELECT userName,password FROM Login", conn);
DataSet ds = new DataSet();
da.Fill(ds, "Login");
DataTable dt = ds.Tables["Login"];
	For(int i=0; i<dt.columns.count;i++)>
	{
		For(int j=0;i<rows.count;j++)>
		{
			If(txtUsrName.text == dt.Rows[i].toString && txtPassword.text==dt.Rows[j].tostring)
			{
				MessageBox.show("Your login successful");
			}
		}
	}


我知道这对某人来说非常容易.但是我有很多尝试解决此问题的方法,但是我不知道在此for循环中使用了哪种逻辑.
如果此代码无效,请给我其他任何想法.

请帮忙.


I know it is very easy for someone. But I had lot of try to solve this but I don’t know which logic is used in this for loop.
If this code is not effective then give me any other idea.

Please help.

推荐答案

SQL查询登录ID的条件为" WHERE ".

1.首先在登录屏幕上接受用户的LoginID和密码.
2.借助登录ID从数据库中获取记录.
3.如果没有记录,则显示消息您尚未创建帐户".
4.如果记录存在,则从UserTable中选择密码,其中UserName =" UserName""
5.如果不存在任何记录,则显示消息密码错误,请重试".

检查以下链接, c#中的登录页面 [
Where is "WHERE" condition in your SQL Query for login ID.

1. First accept LoginID and Password from user on login screen.
2. with the help of Login ID fetch record from database.
3. if no record exist then show message "you have not created your account".
4. if record exist then, "Select Password From UserTable Where UserName = ''UserName''"
5. if no record exist then show message "Wrong Password, Please Try Again".

check following link, login page in c#[^]


"SELECT userName,password FROM Login where userName='" + txtUserName.Text + "' AND password='" + txtPassword.Text + "'"



然后检查dt.rows.count值是否为0,然后登录失败,如果它获得行,则登录成功



Then check dt.rows.count value if it is 0 then login fail and if it gets row then login successfully


这篇关于我该如何解决C#数据库的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆