开发者

C# TableAdapter.Update() is using UPDATE rather than INSERT

开发者 https://www.devze.com 2022-12-24 07:49 出处:网络
SELECTWO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged,
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 becaus开发者_JAVA技巧e 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?


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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消