[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Accecced with an instance reference.

lblLoginCounts.Text = user.GetUserLoginCounts(Int32.Parse(Page.User.Identity.Name)).ToString();
Error      1      Static member 'UserDB.UsersDB.GetUserLoginCounts(int)' cannot be accessed with an instance reference; qualify it with a type name instead      D:\Inetpub\wwwroot\omegalove\Default.aspx.cs      32      43      D:\...\omegalove\

 public static int GetUserLoginCounts(int userID)
        {
            // create data object and params
            SqlDataReader dataReader = null;
            int iCounts = 0;

            // create params for stored procedure call
            Database data = new Database();

            SqlParameter[] prams =
                  {                    
                        data.MakeInParam("@iUserID" ,SqlDbType.Int, 4, userID)                        
                  };

            // run the stored procedure
            data.RunProc("prcUserGetLoginCounts", prams, out dataReader);
            while (dataReader.Read())
                iCounts = dataReader.GetInt32(0);
            dataReader.Close();

            return iCounts;
        }
UserDB.UsersDB user = new UserDB.UsersDB();
                
                SqlDataReader reader = user.GetUserInfo(Int32.Parse(Page.User.Identity.Name));
                while (reader.Read())
                {
                    lblUserName.Text = reader.GetString(1);
                    lblFirstName.Text = reader.GetString(2);
                    lblLastName.Text = reader.GetString(3);
                    lblZodiacSign.Text = reader.GetString(6);
                    lblAge.Text = reader.GetInt32(7).ToString();
                    lblGender.Text = (reader.GetInt32(8) == 0) ? "Male" : "Female";
                    lblDateOfBirth.Text = reader.GetDateTime(9).ToString("d");
                    lblLastOnline.Text = reader.GetDateTime(15).ToString();
                    lblLocation.Text =  reader.GetString(22).ToString() + ", " + GetProvincesorStatesName(reader.GetString(20).ToString()) + ", " + GetCountryName(reader.GetString(19));
                    lblLoginCounts.Text = user.GetUserLoginCounts(Int32.Parse(Page.User.Identity.Name)).ToString();
 
                }

Open in new window

0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 2
  • 2
1 Solution
 
vs1784Commented:
Do one of the below
1. Change
    public static int GetUserLoginCounts(int userID)
                TO
    public int GetUserLoginCounts(int userID)

2.Change
    lblLoginCounts.Text = user.GetUserLoginCounts(Int32.Parse(Page.User.Identity.Name)).ToString();
                     TO
    lblLoginCounts.Text = UsersDB.GetUserLoginCounts(Int32.Parse(Page.User.Identity.Name)).ToString();

Hope it helps

Thanks

0
 
mathieu_cuprykAuthor Commented:
Conversion failed when converting the nvarchar value 'macupryk' to data type int.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting the nvarchar value 'macupryk' to data type int.

Source Error:


Line 208:            // run the stored procedure
Line 209:            data.RunProc("prcUserGetLoginCounts", prams, out dataReader);
Line 210:            while (dataReader.Read())
Line 211:                iCounts = dataReader.GetInt32(14);
Line 212:            dataReader.Close();
 
0
 
vs1784Commented:
It is altogether different error and not related to above. Please check that column is returning a text value and you are trying to convert it into integer.
0
 
mathieu_cuprykAuthor Commented:
I need to pass the userid not the username?
    lblLoginCounts.Text = UsersDB.GetUserLoginCounts(Int32.Parse(Page.User.Identity.Name)).ToString();
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now