Solved

Object Reference Error message in C#

Posted on 2015-02-16
2
73 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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