Data Adapter vs SQLCommand
I am confused about the SQL Data Adapter in ADO.Net.
What is the difference between the below:
SqlDataAdapter adapter = new SqlDataAdapter("Select * from Course", sqlconn);
and
SqlCommand Command = new SqlCommand("Select * from Course", sql开发者_Python百科conn);
Can someone please explain?
The basic answer is: Not a lot in the guts of it.
SQLDataAdapter uses SQLCommand
The main differences are:
- DataAdapter can populate directly into a DataTable, the command returns a DataReader
- DataAdapter can use multiple Commands to support Select, Insert, Update and Delete commands
So you would use Command to get a DataReader to iterate once over everything it returns.
You would use DataAdapter to put it all into a DataTable to reuse it, and to support pushing data back to the DB server.
精彩评论