开发者

Can a DataTable be used to update the DB?

If I bind a DataViewGrid to a DataTable, and change the data in the grid,

  1. How does the DataTable get notified of these changes?
  2. Does the DataTable automatically update the DB?
  3. If not, and I have to do it manually, how do I find out what the changes are?
  4. Does it make a difference if the DataTable was populated from a DataReader or something else?

Or the "big picture" question:

Am I doing this all wrong?

I have a database with one table, and I need to display this table and allow editing it. I don't have any fancy designers since this is a custom (not by me) database type and they only provide DataProvider (is that what it is called?) classes like DataReader, DataAdapter, DataSet, DataTable, etc., but no design-time support. I am also glad for an opportunity to learn how to do all this in code and not with code-generators, but am getting very confused. Until 开发者_如何学编程now I always draged-and-dropped all my data needs, not even knowing if I was using readers or sets or whatever.

Thanks a lot.

BTW, are DataTables disconnected, that is in memory?


You have to use the DataAdapter and specify the Delete, Insert and Update commands. This is a decent explanation.

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/d402f6f4-52c6-48e3-88a6-4d6fbececf8a/


2 - No DataTable is disconnected, so you will need to get the changes back to the Database.

3 - DataTable.GetChanges()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜