Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'GET OR SET ACCESSOR EXPECTED' mean?

Tags:

c#

oop

asp.net

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using System.Data.SqlClient;

public partial class RepeaterEx2 : System.Web.UI.Page {
    SqlConnection cn = null;
    SqlDataAdapter da = null;
    DataSet ds = null;
    String strSqlQuery = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        cn = new SqlConnection();
        cn.ConnectionString = "Server=(local);Data base=TestDb;Uid=sa;Password=123";
        if (!Page.IsPostBack)
        {
        }

    }
    void BindEmpData
    {
        SqlDataAdapter da=new SqlDataAdapter( "select e.ENO,e.ENAME,e.JOB,e.SAL,d.DNAME form EMPLOYEE e,DEPARTMENT d where e.DNO=d.DNO",cn);

        da.Fill(ds,"EMPLOYEE");//here showing set or get accessorexpected error at "da"
        Repeater1.DataSource=ds.Table["EMPLOYEE"];
        Repeater1.DataBind();

    }
}

I'm getting this error:

A get or set accessor expected

How do I resolve this error?

like image 775
DevOpsGeek Avatar asked Dec 27 '13 16:12

DevOpsGeek


2 Answers

You need parentheses after the function name here:

void BindEmpData()
{
    ...
} 

Also, you'll want to make sure you initialize the DataSet correctly:

void BindEmpData()
{
    SqlDataAdapter da = new SqlDataAdapter("select e.ENO,e.ENAME,e.JOB,e.SAL,d.DNAME form EMPLOYEE e,DEPARTMENT d where e.DNO=d.DNO",cn);
    DataSet ds = new DataSet();
    da.Fill(ds,"EMPLOYEE"); 
    Repeater1.DataSource = ds.Table["EMPLOYEE"];
    Repeater1.DataBind();
} 

And at this point you can remove the ds and da class members, since they are no longer being used (they've been replaced by function variables).

like image 75
p.s.w.g Avatar answered Oct 16 '22 06:10

p.s.w.g


Parentheses is required to differentiate a method from a property that requires the get/set syntax

like image 5
madhu131313 Avatar answered Oct 16 '22 07:10

madhu131313