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();
}
}
我收到了这个错误:
期望获取或设置访问者
如何解决此错误?
答案 0 :(得分:35)
这里的函数名后面需要括号:
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();
}
此时您可以删除ds
和da
类成员,因为它们不再被使用(它们已被函数变量替换)。
答案 1 :(得分:3)
需要括号来区分方法和需要get/set syntax
的属性