问题
I'm using SqlDataAdapter.Update(DataTable) to throw a table at the database, but the SqlDataAdapter ignores my InsertCommand to write its own, which only sends the primary key and all the rows that can be null if they want. How do I get it to behave?
I step through the code before and after I call Update(). Before, it's my InsertCommand. After, it's the SqlDataAdapter's.
Edit: I don't especially want to post code samples because I can take the row I have and write my own SqlCommand object that works easily enough. I'm more interested in reasons why Update would decide that the InsertCommand I pass it isn't good enough so I can go digging through my own code -- this whole thing was supposed to be a timesaver.
回答1:
Right, after lots of digging I found out that I needed to call EndEdit on my rows when I was done with them so the changes I made weren't being discarded by the DataTable. As I said, I wasn't doing anything other than calling SqlDataAdapter.Update(DataTable).
来源:https://stackoverflow.com/questions/832874/sqldataadapter-update-doesnt-work