我有一个简单的注册页面,在提交页面内容(用户名和密码)后,我需要为用户分配一个角色。我从 WSAT GUI 创建了 2 个角色(管理员和成员)。
那我怎么给他分配“成员角色”
这是我的注册表..
protected void Button1_Click(object sender, EventArgs e)
{
string EPass = Helper.ComputeHash(TextBox2.Text, "SHA512", null);
String var = System.Configuration.ConfigurationManager.ConnectionStrings["KKSTechConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(var);
String str = @"insert into Users (Username, Pass, EmpID, Rolename)
values(@Username, @Pass, @EmpID, @Rolename)";
SqlCommand cmd = new SqlCommand(str, conn);
cmd.CommandText = str;
cmd.CommandType = CommandType.Text;
try
{
var userName = TextBox1.Text;
conn.Open();
cmd.Parameters.AddWithValue("@Username", TextBox1.Text);
cmd.Parameters.AddWithValue("@Pass", EPass.ToString());
cmd.Parameters.AddWithValue("@EmpID", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@Rolename", DropDownList2.SelectedValue);
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
dbo.Users:用户名(PK)| 通行证 | EmpID (FK) | 角色名