Solved

Object Reference Error message in C#

Posted on 2015-02-16
2
77 Views
Last Modified: 2015-02-16
I'm a noob to C# so please excuse me if this is a dumb question. I created a button click event to create an account. I want to pass the populated fields to a database. I've created two different .CS sheets. The first I'm having a problem with. The error message I receive is "An object reference is required for the non-static field, method, or property 'clsDataLayer.CreateUser(string, string, string, string)'. Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;


namespace WSC1
{
    public partial class Registration : System.Web.UI.Page
    {
       
       private void btnCreateAccount_Click(object sender, EventArgs e)
        {
           
            if (TxtPassword1.Text != custPassword.Text)
            {
                lblPasswordStatus.Text = "The passwords do not match";

            }



            if (clsDataLayer.CreateUser(custFName.Text , custLName.Text , custEmail.Text , custLogin.Text , custPassword.Text ) == true)
            {
                lblNewCustomerStatus.Text = "The user was successfully added!";
            }

            else
                lblNewCustomerStatus.Text = "The user could not be added";
        }

       
    }

}
0
Comment
Question by:Robin Harris
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40612180
Try putting the word static in the cs file in front of the CreateUser function.

Roughly
public bool CreateUser((string, string, string, string, string)
change to
public static bool CreateUser((string, string, string, string, string)
0
 

Author Comment

by:Robin Harris
ID: 40612193
That worked. Thank you so much
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question