Home > Back-end >  entuser.User_Name.Value = 'entuser.User_Name.Value' threw an exception of type 'Syste
entuser.User_Name.Value = 'entuser.User_Name.Value' threw an exception of type 'Syste

Time:10-11

currently i am working a one project and i got this type of error. i excuted the procedure and in debugging mode prcedure pass the data to entity file but when i go back to aspx page so that time i got this null exception. how can i resolve. any one help me?.

UserDAL file

this is a prcedure

        public UserENT PR_IP_User_LoginUser(SqlInt32 UserID)
        {
            using (SqlConnection objconn = new SqlConnection(ConnectionString))
            {
                objconn.Open();
                using (SqlCommand objcmd = objconn.CreateCommand())
                {

                    try
                    {
                        #region Prepaed Command
                        objcmd.CommandType = CommandType.StoredProcedure;
                        objcmd.CommandText = "PR_IP_User_LoginUser";
                        objcmd.Parameters.AddWithValue("@UserID", UserID);
                        #endregion

                        UserENT entuser = new UserENT();
                        #region Read and set controls
                        using (SqlDataReader objSDR = objcmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["User_Name"].Equals(DBNull.Value))
                                {
                                    entuser.User_Name = Convert.ToString(objSDR["User_Name"].ToString().Trim());
                                }
                                if (!objSDR["Password"].Equals(DBNull.Value))
                                {
                                    entuser.Password = Convert.ToString(objSDR["Password"].ToString().Trim());
                                }
                                if (!objSDR["User_ID"].Equals(DBNull.Value))
                                {
                                    entuser.User_ID = Convert.ToInt32(objSDR["User_ID"]);
                                }
                                if (!objSDR["ContactNo"].Equals(DBNull.Value))
                                {
                                    entuser.ContactNo = Convert.ToString(objSDR["ContactNo"]);
                                }
                                if (!objSDR["Email_ID"].Equals(DBNull.Value))
                                {
                                    entuser.Email_ID = Convert.ToString(objSDR["Email_ID"]);
                                }
                                if (!objSDR["Is_Admin"].Equals(DBNull.Value))
                                {
                                    entuser.Is_Admin = Convert.ToBoolean(objSDR["Is_Admin"]);
                                }

                            }
                            return entuser;
                        }
                        #endregion


                    }
                    catch (Exception e)
                    {
                        Message = e.InnerException.Message;
                        return null;
                    }
                    finally
                    {
                        objconn.Close();
                    }
                }
            }
        }
        #endregion

on client side or can say aspx page

on button click event

    protected void btnLogin_Click(object sender, EventArgs e)
    {

        
            #region Server Side Validation
            String strerr = "";
            if (txtusername.Text.Trim() == "")
            {
                strerr  = "Enter UserName";
            }
            if (txtpassword.Text.Trim() == "")
            {
                strerr  = "Enter Password";
            }

            if (strerr != "")
            {
                lblMessage.EnableViewState = true;
                lblMessage.Text = strerr;
            }
            #endregion

            #region Gather Data

            SqlString Username, userpass;
            if (txtusername.Text.Trim() != "")
            {
                Username = txtusername.Text.Trim();
            }
            if (txtpassword.Text.Trim() != "")
            {
                userpass = txtusername.Text.Trim();
            }


            #endregion

            UserBAL baluser = new UserBAL();
            UserENT entuser = new UserENT();
            SqlInt32 UserID_Res;
            SqlString User_name_res, User_Password_res;
            SqlInt32 userid = Convert.ToInt32(txtuserid.Text.Trim());
            if (Request.QueryString["User_ID"] == null)
            {
                if (baluser.Login(userid) != null)
                {
                    User_name_res = entuser.User_Name.Value.ToString().Trim();
                    UserID_Res = Convert.ToInt32(entuser.User_ID.Value);
                    User_Password_res = entuser.Password.Value.ToString().Trim();

                    if (User_name_res == txtusername.Text.Trim() || User_Password_res == txtpassword.Text.Trim())
                    {
                        Response.Redirect("AddSubject.aspx");
                    }
                    else
                    {
                        Response.Redirect("AddTopic.aspx");
                    }
                }
            }
        



        #endregion

CodePudding user response:

The C# code associated with a ".aspx" page (or code behind) is executed on the server side.

I assume that UserBAL.Login() function returns the user's data once logged in. It may be necessary to get the returned object.

On button click event :

protected void btnLogin_Click(object sender, EventArgs e)
{
    ...
    
    UserENT entuser = baluser.Login(userid);
    if (entuser  != null)
    {
        ...

CodePudding user response:

Thanks every one who help to solve my error. now i resolve my error. i Just pass the data to procure and check the data in procedure and return Boolean value. Thanks Again :)

  • Related