An object reference is required for the non-static field method or property

  • Thread starter Thread starter Windows_Is_My_Idea
  • Start date Start date
W

Windows_Is_My_Idea

Guest
I'm trying to access labelNummer.Text from my User Control in my form. But now i get the error an object reference is required for the non-static field method or property. I need help with this.

Upartijen.labelNummer.Text gives the error in my form.


if (idPartijen.Contains(uPartijen.labelNummer.Text))
{
con.SqlQuery("SELECT * FROM `kandidaat` where `partijnummer` =@nummer ");
con.Cmd.Parameters.Add("@nummer", MySql.Data.MySqlClient.MySqlDbType.VarString).Value = uPartijen.labelNummer.Text;

foreach (DataRow dr in con.QueryEx().Rows)
{
uKandidaten proitem = new uKandidaten(this);

Voornaam = dr[2].ToString();
Achternaam = dr[3].ToString();
NummerKandidaat = dr[6].ToString();

proitem.KandidaatNaam = Voornaam;
proitem.KandidaatAchterNaam = Achternaam;
proitem.KandidaatNummer = NummerKandidaat;

kandidatenlist.Add(proitem);
idPartijen.Add(NummerKandidaat);

}
panelPartijen.Controls.Clear();
panelPartijen.Controls.AddRange(kandidatenlist.ToArray());

}
This is my User Control

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;


namespace Stemcomputer
{
public partial class uPartijen : UserControl
{
public uPartijen(StemSysteem form1)
{
InitializeComponent();
_Form1 = form1;
}



public StemSysteem _Form1;

public string Nummer;

public string KandidaatNummer
{
get
{
return labelNummer.Text;
}

set
{
labelNummer.Text = value;
}
}

Continue reading...
 
Back
Top