什么是“GET或预期set访问”是什么意思? [英] What does 'GET OR SET ACCESSOR EXPECTED' mean?

查看:197
本文介绍了什么是“GET或预期set访问”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

get或set访问有望

A get or set accessor expected

我如何解决这个问题?

推荐答案

您需要的函数名在此之后的括号:

You need parentheses after the function name here:

void BindEmpData()
{
    ...
} 

另外,你要确保你初始化的DataSet 正确的:

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();
} 

而在这一点上,你可以删除和 DA 类的成员,由于不再使用它们了 DS (他们被函数变量替换)。

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

这篇关于什么是“GET或预期set访问”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆