从网格的基础上删除行. [英] deleting row from the grid on slection bases.
本文介绍了从网格的基础上删除行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用delete sql查询从数据库中删除特定用户的角色.但是问题是,如果用户具有多个角色.而不是从数据库中删除特定用户的所有角色.我可以基于选择删除行吗?
我应该用什么方法做到这一点.
i am using delete sql query to delete role of a particular user form the database.. but the problem is that.. if user has more than one role. than its erasing all the role of a particular user from the database. can i delete row on selection bases?
what approach i should use to do that.. ??
protected void _rowdeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lbldeletename = (Label)row.FindControl("lblusername");
MAconn.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM Roles WHERE UserId = (SELECT u.UserId FROM Users u WHERE u.UserName = @UserName", MAconn);
cmd.Parameters.AddWithValue("@UserName", lbldeletename.Text);
cmd.ExecuteNonQuery();
MAconn.Close();
bind();
}
推荐答案
从用户删除角色需要REVOKE命令,此链接将提供有关此信息的更多详细信息:
http://beginner-sql-tutorial.com/sql-grant-revoke-privileges- role.htm [ ^ ]
Deleting roles from a user requires a REVOKE command, this link would provide more details on this:
http://beginner-sql-tutorial.com/sql-grant-revoke-privileges-roles.htm[^]
您应该传递角色ID来查询.....
You Should pass role id in to query.....
SqlCommand cmd = new SqlCommand("DELETE FROM Roles WHERE RoleId =@RoleId AND UserId = (SELECT u.UserId FROM Users u WHERE u.UserName = @UserName", MAconn);
这篇关于从网格的基础上删除行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文