Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

c# - What does 'GET OR SET ACCESSOR EXPECTED' mean?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...