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?
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).
Parentheses is required to differentiate a method from a property that requires the get/set syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With