2

I am using asp.net 2008 repeater control. I am trying to refresh the repeater control when a button is clicked, it shows me duplicated values, that means its appending the same values once again. Here is my code

 public void LoadRepeater1()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServerConnection"].ConnectionString);
        String sql;
        sql = "select * from FeeCollection Where AdminNo='"+lblstano.Text+"'";
        cmd = new SqlCommand(sql, con);
        da = new SqlDataAdapter(sql, con);
        da.Fill(ds, "FeeCollection");
        dt = ds.Tables["FeeCollection"];

        Repeater4.DataSource = dt;
        Repeater4.DataBind();
        con.Close();


    }

 protected void btnMedical_Click(object sender, EventArgs e)
    {
        LoadRepeater1();
    }

I want to remove the existing data and refresh the data instead of appending.

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
AjayR
  • 4,169
  • 4
  • 44
  • 78

1 Answers1

1

Not sure where ds (DataSet) in instantiated. Try to instantiate the DataSet/DataTable within the LoadRepeater1() method.

public void LoadRepeater1()
    {
        con = new SqlConnection(ConfigurationManager
         .ConnectionStrings["SqlServerConnection"].ConnectionString);

        sql = "select * from FeeCollection Where AdminNo=@AdminNo";
        cmd = new SqlCommand(sql, con);
        cmd.Parameters.Add("@AdminNo",System.Data.SqlDbType.VarChar,20).Value=lblstano.Text;
        da = new SqlDataAdapter(cmd);
        DataTable dt=new DataTable();
        da.Fill(dt);
        Repeater4.DataSource = dt;
        Repeater4.DataBind();
    }
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • thank you, I was using global variable for dataset which was not clearing. Now I used local variable and works fine – AjayR Oct 07 '11 at 11:27