views:

500

answers:

2
SELECT        WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, 
                         WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, COALESCE (WO_BreakerRail.Date, @date) AS Date
FROM            indRailType LEFT OUTER JOIN
                         WO_BreakerRail ON indRailType.RailCode = WO_BreakerRail.RailCode AND WO_BreakerRail.Date = @date

I have a DataGridView that is bound to a table adapter. This is the select query I use to fill my adapter. The ID column is going to be null where there are no matching entries from WO_BreakerRail. The update command works fine when I update a row that has data in it. But if I update a row that has no matching info in WO_BreakerRail, it fails because the table adapter thinks it should be updating because I've modified rows in it's row collection, but WO_BreakerRail doesn't have that row. Is there a way to tell the table adapter to use the insert command when ID is null rather than the update command?

+1  A: 

For the rows that does not have data, set the rowstate to new by 
calling dataRow.SetAdded().

Partha Choudhury
A: 

I think the following is what your missing in your add method.

   // ... in your method where your inserting 
        DataRow row = MyDataTable.NewRow();
        // .... add data to row ....
        MyDataTable.Rows.Add(row);
Anthony