0

I have a windows form with a DataGridView databoud to a single table. On the page load i run a query to return a single row in the DataGrid View:

   private void SQL__Edit_Load(object sender, EventArgs e)
    {

        // TODO: This line of code loads data into the 'sQLInfrastructureADD_EDIT.SQLInfrastructure' table. You can move, or remove it, as needed.
        this.sQLInfrastructureTableAdapter.Fill(this.sQLInfrastructureADD_EDIT.SQLInfrastructure);

        {
            SqlDataAdapter sba = new SqlDataAdapter("Select * from dbo.SQLInfrastructure WHERE [Instance] LIKE  '" + label1.Text + "%'", connn);

            System.Data.DataTable data = new System.Data.DataTable();
            sba.Fill(data);
            sQLInfrastructureDataGridView.DataSource = data;
        }



    }

I then have a binding navigator with a save button:

 private void sQLInfrastructureBindingNavigatorSaveItem_Click(object sender,  EventArgs e)
    {
        this.Validate();
        this.sQLInfrastructureBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.sQLInfrastructureADD_EDIT);

    }

When I remove the query the entire table loads and saves with the binding navigator, when I add the query to only load a single row that needs to be edited it does not save the changes to the database. Please instruct me how to run this query and save changes to the database from the results with a binding navigator.

  • The problem is I need to be able to query based on a label Select * from dbo.SQLInfrastructure WHERE [Instance] LIKE '" + label1.Text + "%'" How would I create a save button for the changes in the queried DataGridView? Would I have to write an insert statement, it will always be for a single row. – PoopaSaurasRex Aug 25 '16 at 21:20
  • For DataAdapter approach take a look at [CRUD Operations using DataGridView, DataTable and TableAdapter](http://stackoverflow.com/a/36274706/3110834). – Reza Aghaei Aug 25 '16 at 21:45
  • For TableAdapter approach take a look at [How to: Create parameterized TableAdapter queries](https://msdn.microsoft.com/en-us/library/ms171905.aspx) – Reza Aghaei Aug 25 '16 at 21:53
  • Currently you are assigning a new data table '`data`' to grid while you try to save another one '`this.sQLInfrastructureADD_EDIT`'. Surely there is no changes in '`this.sQLInfrastructureADD_EDIT`' because you bind the grid to the other one. – Reza Aghaei Aug 25 '16 at 21:55

0 Answers0