error while doing page login for ASP.NET application and SQL server

65 Views Asked by At
{
    public DataTable EmpLoginbyId()
    {
        SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true");
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();
        SqlDataAdapter adp = new SqlDataAdapter("EmpLoginbyId", con);
        cmd.CommandType = CommandType.StoredProcedure;
        adp.Fill(dt);
        return dt;
    }
    public void EmpLogin(string Email, String Password)
    {

        SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true");
        SqlCommand cmd = new SqlCommand("EmpLogin", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Email", Email);
        cmd.Parameters.AddWithValue("@passward", Password);



        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    } 

protected void Button1_Click(object sender, EventArgs e) {

        try
        {
            Session["UID"] = Lgn.EmpLogin(TxtUN.Text, TxtPW.Text);
            int? UID = Convert.ToInt32(Session["UID"].ToString());
            DataTable dt = new DataTable();
            dt = Lgn.EmpLoginbyId(Convert.ToInt32(UID));
            string Username = dt.Rows[0]["UserName"].ToString();
            //string Username = dt.Rows[0]["UserName"].ToString();
            Session["ETID"] = Convert.ToInt32(dt.Rows[0]["UserTypeID"].ToString());
            if (Username == null)
            {
                Session["UserName"] = Username.ToString();

            }
            if (UID.HasValue)
            {
                Response.Redirect("Admin.aspx");
            }


        }
        catch { }
    }

and this is my class code it gives me this error Error 1 Cannot implicitly convert type 'void' to 'object'
Error 2 No overload for method 'EmpLoginbyId' takes 1 arguments

1

There are 1 best solutions below

0
Pratik Gaikwad On

First error is there because EmpLogin is returning void and you are trying to assign it to some object which is invalid. So either return some value from the function or remove assignment to session object.

Second error is valid since EmpLoginById doesn't have any parameter in its signature. So either modify signature or call to the function by removing UID.