Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. DataGridView strange

DataGridView strange

Scheduled Pinned Locked Moved C#
cssdatabasehelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muharrem
    wrote on last edited by
    #1

    I have following in my form MySqlDataAdapter da; DataSet ds; private void MyForm_Load(object sender, EventArgs e) { ds = new DataSet(); string strSQL = "SELECT A,B,C,D FROM MyTable"; da = new MySqlDataAdapter(strSQl,myConnection); da.Fill(ds, "Example"); gridForExample.DataSource = ds.Tables["Example"]; } private void btnRefresh_Click(object sender, EventArgs e) { da.Fill(ds, "Example"); } So, MyTable has only six rows in database. Every time da.Fill(ds, "Example"); executes grid view showing 6 more but same rows. I mean 6 then 12 then 18 and so on. But I expect to see only 6 rows, don't I? Or am I mistaken? Please help. Thanks

    P 1 Reply Last reply
    0
    • M muharrem

      I have following in my form MySqlDataAdapter da; DataSet ds; private void MyForm_Load(object sender, EventArgs e) { ds = new DataSet(); string strSQL = "SELECT A,B,C,D FROM MyTable"; da = new MySqlDataAdapter(strSQl,myConnection); da.Fill(ds, "Example"); gridForExample.DataSource = ds.Tables["Example"]; } private void btnRefresh_Click(object sender, EventArgs e) { da.Fill(ds, "Example"); } So, MyTable has only six rows in database. Every time da.Fill(ds, "Example"); executes grid view showing 6 more but same rows. I mean 6 then 12 then 18 and so on. But I expect to see only 6 rows, don't I? Or am I mistaken? Please help. Thanks

      P Offline
      P Offline
      paas
      wrote on last edited by
      #2

      There is no indication in this code sample that you have cleared your dataset from its first or subsequent fills, so you are just adding another 6 rows to the previous number of rows each time you do a refresh. You should do a ds.Clear() prior to the Fill if you do not want to keep appending rows to the dataset.

      M 1 Reply Last reply
      0
      • P paas

        There is no indication in this code sample that you have cleared your dataset from its first or subsequent fills, so you are just adding another 6 rows to the previous number of rows each time you do a refresh. You should do a ds.Clear() prior to the Fill if you do not want to keep appending rows to the dataset.

        M Offline
        M Offline
        muharrem
        wrote on last edited by
        #3

        Thanks for the answer. I don't know how I miss that point? Anyway thanks again.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups