如何使用该角色登录 [英] How to login with that role
本文介绍了如何使用该角色登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码登录回合我不知道我该怎么回事?????我想如果管理员打开form1如果用户打开form2
我尝试过:
i use this code to login in bout i don't know what should i bout in ????? i want if it admin open form1 if user open form2
What I have tried:
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from tbladmin where username='" + txtusername.Text.Trim() + "' and password='" + txtpassword.Text.Trim() + "'", sqlcon);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
if (dtbl.Rows[0][0].ToString() == "1")
{
SqlDataAdapter sda5 = new SqlDataAdapter("select role from tbladmin where username='" + txtusername.Text.Trim() + "' and password='" + txtpassword.Text.Trim() + "'", sqlcon);
DataTable ds5 = new DataTable();
sda5.Fill(ds5);
String value5 = ds5.Rows[0][0].ToString();
Debug.WriteLine("value is : " + value5);
if (????????? = 'admin')
{
推荐答案
您不需要SqlDataAdapter和DataTable来得到一个值,你可以使用更轻量级的 SqlDataReader ,参见这里的示例: [ ^ ]
You don't need SqlDataAdapter and DataTable to get a value, you can use the more lightweight SqlDataReader, see example here: Retrieving Data Using a DataReader | Microsoft Docs[^]
string value5 = reader.GetString(0));
还使用参数化查询,尤其是在像这样的安全敏感查询中!
请参阅: c# - 如何使用sql参数进行选择查询? - 堆栈溢出 [ ^ ]
如果在 tbladmin 中找到值,则表示找到了管理员,其他用户可以在 tbluser 中找到。
Also use parameterized queries, especially in security sensitive queries like this one !
See: c# - How to use sql parameters for a select query? - Stack Overflow[^]
If a value is found in tbladmin, it means that an admin was found, other users can be found in tbluser.
这篇关于如何使用该角色登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文