views:

528

answers:

3

I'm using 2005 Windows Forms in C#. I've only been working at this for a day, so go easy please.

I'd like to have a submit button that saves changes to a DataGridView. I've gotten data into the DGV and can edit, but am stuck on the Update().

I've created an .xsd named scDB and one DataTable called - SSIS Configurations Staging. I then added a new query that takes a parameter.

Here is my code so far:

//Declared at top of form class    
scDBTableAdapters.SSIS_Configurations_StagingTableAdapter myStagingTableAdapter = new scDBTableAdapters.SSIS_Configurations_StagingTableAdapter();


//After a form event            
stagingGrid.DataSource = myStagingTableAdapter.GetDataBy(filterName.Text.ToString());

//On Submit click:

myStagingTableAdapter.Update(?What Goes Here?);

What gets passed to the Update method? I know it needs a dataTable, but I don't know how to reference what is in the GridView. In most code examples people define the DataTable - but I do not. I assume this is being done behind the scenes when I created the TableAdapter. Thanks for the help.

+1  A: 

Update on a table-adapter needs a DataSet.

You need to instantiate a scDB DataSet with the table, update that table and call to Update for the table-adapter.

FerranB
Yes, but I don't define any of this, how can I find what it is called? If I try to use scDB it tells me it is a type...which makes sense.
Sam
+1  A: 

Sam,

the update needs a table so you could try something like:

TableType table = (TableType) stagingGrid.DataSource;
myStagingTableAdapter.Update(table);

where you'll have to substitute TableType with something appropriate.

But a better approach would be to use drag-and-drop and learn form the code.

  1. Select Data|View Datasources. Your dataset should be visible in the DataSources Window.
  2. Drag a table to a (new) form. VS2005 will add a load of components and a few lines of code.

The form will now have a instance of the dataset and that is your reference point for Adapter.Fill and .Update methods.

Henk Holterman
Yes, that worked, but I'll try what you've mentioned. Thanks.
Sam
A: 

If you've configured the proper TableAdapter to go with the DataTable specified (Right-Click on the TableAdapter section and select "Configure...'), you'll have a wide variety of options.

After doing this on my own DataTables I'm able to update by

  • Strongly Typed DataTable
  • DataSet
  • DataRow DataRow() - Array of DataRows if multiple require updating
  • Individual Columns (provided you have unique key to tie the row to)
Dillie-O