Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > using dataadapter/datasets with joined tables to fill/edit an datagridview
 

using dataadapter/datasets with joined tables to fill/edit an datagridview

I have two tables in my datasource, feeder type and feederserialnumbers

I need to show fields from both tables in my datagridview then beable to update one of the tables.

SELECT FeederSerialNumbers.SerialNumber, FeederSerialNumbers.Site, [Feeder Type].[feeder cost], [Feeder Type].[feeder type], FeederSerialNumbers.status,
FeederSerialNumbers.ActiveDate
FROM [Feeder Type] INNER JOIN
FeederSerialNumbers ON [Feeder Type].[Type Id] = FeederSerialNumbers.TypeId

when the user clicks a save button I wanted to update any changes to the datagridview

Ljhopkins  Monday, May 05, 2008 6:19 PM

Hi Ljhopkins,

The DataSet designer can only generate the InsertCommand, UpdateCommand and DeleteCommand from SelectCommand which returns items from more than one table. To enable the auto-generation, the SelectCommand must have the following feature.

· Returns items from single-table

· Returns at least one primary key or unique column

In your case, your SelectCommand returns item from two tables, you need to create the InsertCommand, UpdateCommand and DeleteCommand yourself to make the DbDataAdapter to work.

Code Snippet

........

myTableAdapter.DeleteCommand = sqldbdelectcommand;

myTableAdapter.UpdateCommand = sqldbupdatecommand;

myTableAdapter.InsertCommand = sqldbinsertcommand;

........

More information, please check:

· http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

· http://support.microsoft.com/kb/308507

Hope this helps.
Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, May 09, 2008 5:26 AM

Hi Ljhopkins,

The DataSet designer can only generate the InsertCommand, UpdateCommand and DeleteCommand from SelectCommand which returns items from more than one table. To enable the auto-generation, the SelectCommand must have the following feature.

· Returns items from single-table

· Returns at least one primary key or unique column

In your case, your SelectCommand returns item from two tables, you need to create the InsertCommand, UpdateCommand and DeleteCommand yourself to make the DbDataAdapter to work.

Code Snippet

........

myTableAdapter.DeleteCommand = sqldbdelectcommand;

myTableAdapter.UpdateCommand = sqldbupdatecommand;

myTableAdapter.InsertCommand = sqldbinsertcommand;

........

More information, please check:

· http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

· http://support.microsoft.com/kb/308507

Hope this helps.
Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, May 09, 2008 5:26 AM

You can use google to search for other answers

Custom Search

More Threads

• Can someone explain why this SetCurrentCellAddressCore override does not work?
• Cannot Update Multiple Tables(Set of useful functions)
• Databinding ComboBox Woes. AARRGGHH!
• Handling identity columns in a data bound GridDataView
• openFileDialog filename problem
• Connection pool timing out
• Can the DataGridView accept Enter instead of Shift+Enter for a new line?
• Can't get Filter right.
• Data grid view
• Drag and Drop Datasources have all stopped updating