如何使用SQL 2008创建C#登录表单 [英] How to create C# login form using SQL 2008

查看:55
本文介绍了如何使用SQL 2008创建C#登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我设计了一个登录表单,我希望它能像这样运行,



用户将输入他/她的用户名和密码到texboxes。

正确的详细信息必须来自数据库。

如果用户输入错误的详细信息并且必须限制用户。



你可以在做代码时评论,因为我不想做疯狂的东西。





感谢您的帮助。

Hi Everyone,


I have designed a login form and i want it to function like this,

User will enter his/her username and password to texboxes.
The correct details must come from the database.
If the user enters the wrong details and must restrict the user.

Can you please comment when doing the codes because i dont want to do craming stuff.


Thanks for your help.

推荐答案

参见如何创建登录页面 [ ^ ]



干杯,

Edo
See How to create Login page[^]

Cheers,
Edo


如果它是sql server数据库实例的名称和密码,你可以以编程方式生成一个连接字符串。


或者如果用户信息存储在表格中,你可以设置查询。

这样的事情:

you can generate a connectionstring programarically if its usre name and password of sql server database instance.

or if user information is stored inside a table you can set up a query.
some thing like this:
if    exists
(
   Select   UserName,Password   From Users    Where UserName = @UserName 
   And Password  = @Password
) return 1
else
  return 0


试试这个我已经实现了这个

Try this I''ve already implemented this
public bool login(string id, string entered_password)
    {
 public SqlConnection con = new SqlConnection("Data Source=[Server Name];Initial Catalog=[Database Name];User ID=[User];Password=[Password]");
        con.Open();
        string query = "SELECT [userpass] FROM userlogin WHERE [userid]=@id";
        SqlCommand cmdChk = new SqlCommand(query, con);
        cmdChk.Parameters.Add("@id", SqlDbType.VarChar).Value = id;
        SqlDataReader dr = cmdChk.ExecuteReader();
        int count = 0;
        string password = "";
        while (dr.Read())
        {
            count++;
            password= dr[0].ToString();
        }

        dr.Close();
        con.Close();
        if (count < 1)
        {
            return false;

        }
        else
        {
            if (password == entered_password)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }


这篇关于如何使用SQL 2008创建C#登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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