tags:

views:

18

answers:

1

Hello all,

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", sqlconn);

Can someone please explain?

Thanks

A: 

Hi Mage.

The basic answer is: Not a lot in the guts of it.

SQLDataAdapter uses SQLCommand

The main differences are:

  1. DataAdapter can populate directly into a DataTable, the command returns a DataReader
  2. 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.

Roger Willcocks
Can you use the and SQLCOmmand to UPDATE or INSERT tables and then use the adapter.InserCommand or adapter.UdateCommand to make the changes back to the database?
Mage
Basically, yes. That's what the insert/update/delete commands are on the data adapter for.
Roger Willcocks

related questions