You must Sign In to post a response.
  • Category: ASP.NET

    How to create role id on user login


    Are you looking for a way to create role id on user login ? then read this thread to know more about it



    Hi,
    am create a Login Page . then i want to check roleid in the logintable.
    my code is..
    MySqlCommand cmd = new MySqlCommand("select * from login where empcode =@empcode and password=@password ", cn);



    cmd.Parameters.AddWithValue("@empcode", txtempcode.Text);
    cmd.Parameters.AddWithValue("@password", txtpass.Text);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);


    if (dt.Rows.Count > 0)
    {
    Response.Redirect("Home.aspx");
    }
    else
    {
    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
    }
    }
    roleid is 1,2,3
    using this roleid only i want to login....
  • #756330
    Hi,

    If you want to login for particular roles then in where condition include role id condition too.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #756333
    If you want to loin with the help of role id then you need to keep any auto incremented column in table, on each insertion of user record, separate role id will get created and you can use it
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #756350
    Select the Role from the data base as well, so that you can compare the Role



    if (dt.Rows[0].["RoleId"].ToString() ="1" )
    {
    Response.Redirect("Home.aspx");
    }
    else
    {
    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
    }
    }


    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #760933
    hi
    ancy

    You can change your query include where statement for fetch RoleId data

    try this code


    SqlCommand cmd = new MySqlCommand("select * from login where empcode =@empcode and password=@password and RoleId in(1,2,3)", cn);
    cmd.Parameters.AddWithValue("@empcode", txtempcode.Text);
    cmd.Parameters.AddWithValue("@password", txtpass.Text);
    SqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    Response.Redirect("Home.aspx");
    }
    else
    {
    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
    }


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments