I'm trying to retrieve data from database after clicking view button from windows form, but every time I click on view button the same data in database copied in multiple rows in DataGridView control, instead of retrieving the same data from starting in the DataGridView every time I click on view button.
     //For view button 
        private void button2_Click(object sender, EventArgs e)
        {
                Bi开发者_JAVA技巧ndingSource bindingSource = new BindingSource();
                bindingSource.DataSource = businesslayer.View("Select * from itemmaster"); //passed to business access layer class
                dataGridView1.DataSource = bindingSource;
        } 
//Method in DataAccessLayer class
 public DataTable View(String query)
        {
            //Initialize a connection object
            OpenConn();
            //Initalize a command object with passing string value
            command = new SqlCommand(query, connection);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = command;
            //Fill dataset with a table
            da.Fill(dataset, thisTable);
            return dataset.Tables[thisTable];
        }
Could anyone please tell me how can I solve this problem
BindingSource bindingSource = new BindingSource(); 
dataGridView1.Items.Clear();
bindingSource.DataSource = businesslayer.View("Select * from itemmaster"); //passed to business access layer class 
dataGridView1.DataSource = bindingSource;
Try clearing your gridview before binding it to your datasource.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论