views:

148

answers:

4
+1  A: 

Code 1 is a fetch (hence the dataset which is a data storage object) and code 2 simply runs a command (an insert) into the dbase. However the cmd.CommandText() is commented (and thus isn't set) so that code will actually throw an exception.

EDIT: Have a look here: ADO.Net 2.0 Documentation MSDN

Spence
Aaa, that was my mistakes, it was not commented, and yes it doing queries for 'insert into'. But what is the different from the term of query? code 1 was bind with ' System.Data.SqlClient.SqlDataAdapter()' method, while code2 using ' System.Data.SqlClient.SqlCommand' code??
+1  A: 

The first one gets something from the database, it's a select. The second one does nothing but if the cmd.CommandText is uncommented it performs an insert. They are definitely not examples of doing the same thing in different ways.

Jonas Elfström
+2  A: 

In the first code you are trying to fetch a resultset from database using dataadpater and then filling a dataset with the fill method of dataadapter.

In the second one you are inserting details to a table using ExecuteNonQuery method of SqlCommand object.

rahul
A: 

First one you are selecting and in the second one you are inserting :)

Dataset, and Dataadapter are used to fetch data from database .

Dataadapter act as a bridge between database and dataset .

In your second code says that its for insertion of your data to database.

ExecuteNonQuery says how many rows are affected .

anishmarokey
Ok , thank you all for reply. But if i wanna cameout with a program, which approach should i used? The code 2 seems much more shorter, if looked at the way how the database is connected!!