C#的登录页面。 SQL Server的" sda.Fill(DT); "错误 [英] C# Login page. SQL Server " sda.Fill(dt); " ERROR

查看:1063
本文介绍了C#的登录页面。 SQL Server的" sda.Fill(DT); "错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看这个视频 https://www.youtube.com/watch?v=tcmmCcMs8yU 。它基本上教我如何使用SQL Server创建自己的登录页面。

I was watching this video https://www.youtube.com/watch?v=tcmmCcMs8yU . It basically teaches me how to create my own login page using SQL Server.

那么究竟后,他做了什么,当我点击提交按钮我有一个错误突出 sda.Fill(DT)后; 。我是很新的SQL Server时,请告知

So after following exactly what he did, when I click the submit button I have an error highlighting sda.Fill(dt);. I am pretty new to SQL Server, please advise!

我的代码:

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Glenntdy\Documents\GlennTeoDB.mdf;Integrated Security=True;Connect Timeout=30");        

SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Table where Username='"+txtName.Text + "' and Password = '" +txtPassword.Text + "'",con);

DataTable dt = new DataTable();

sda.Fill(dt);

if (dt.Rows[0][0].ToString() == "1")
{
    this.Hide();

    Main ss = new Main();
    ss.Show();
}
else
{
    MessageBox.Show("Please double check your Username and password");
}

照片错误的:

我!无法提前发布的图片由于信誉不足

I am unable to post picture due to insufficient reputation

感谢

编辑:主要的问题已经解决, 谢谢大家!

EDIT : The main issue have been solved, thanks to all!

我希望我没有违反任何规则,但没有任何人知道如何更改密码文本*打字时,而不是只显示平原密码?只是任何其他网站的登录页面? - 问题已被解决Sohaiby。非常感谢!

Hopefully I am not breaking any rules but does anybody know how to change the password text to * while typing instead of showing just the plain password? Just any other website login page? - Issue have been solved by Sohaiby. Thanks a lot!

EDIT [2]:这个问题已经解决了!

EDIT[2] : The question have been solved!

推荐答案

表是保留关键字,应由括号像包围[表] 。此外,它是的不可以建议构建查询你的方式,因为SQL注入攻击的。了解更多关于 SqlParameters 。还有一件事..你应该使用后关闭SqlConnection。

Table is a reserved keyword and should be surrounded by braces like [Table]. Additionally it is not recommended to construct your query the way you do, because of SqlInjection. Read more on SqlParameters. One more thing.. you should close the SqlConnection after use.

这篇关于C#的登录页面。 SQL Server的" sda.Fill(DT); "错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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