C# winform 权限设置问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 07:24:37
这个是我的部分代码:
SqlDataAdapter adpter1 = new SqlDataAdapter("select * from Login where ID = '" + this.textBox1.Text + "'", connectstr);
SqlCommandBuilder builder1 = new SqlCommandBuilder(adpter1);
DataSet ds = new DataSet();
adpter1.Fill(ds, "Login");

foreach (DataRow row in ds.Tables["Login"].Rows)
{
if (row["Able"].ToString() == "0")
{
///冻结命令
string cmdText = "update [Login] set [Able] = '" + 1 + " '";
///创建连接
SqlConnection myCon = new SqlConnection(connectstr);
///打开数据库
myCon.Open();
//创建执行命令
SqlCommand myCmd = new SqlCommand(cmdText, myCon);
<

//你在此处遍历了全部的行
foreach (DataRow row in ds.Tables["Login"].Rows)
{
//假设Able属性为0的话,就把它改成一
if (row["Able"].ToString() == "0")
{
///冻结命令
string cmdText = "update [Login] set [Able] = '" + 1 + " '";
///创建连接
SqlConnection myCon = new SqlConnection(connectstr);
///打开数据库
myCon.Open();
//创建执行命令
SqlCommand myCmd = new SqlCommand(cmdText, myCon);

///从数据库读取数据
int i = myCmd.ExecuteNonQuery();
if (i == 1)
{
MessageBox.Show("更改成功!");
}
else
{
MessageBox.Show("更改失败!");
}
}
else
{
MessageBox.Show("该管理员已经是超级管理员!");
return;
}
}

所以肯定是会把全部都改成一的。所以条件不能只是
if (row["Able"].ToString() == "0")
至少应该是个这个
if (row["Able"].userName == "userName"&&row["Able"].ToString() == "0")

这里