Click here to Skip to main content
13,090,672 members (43,307 online)
Rate this:
Please Sign up or sign in to vote.
this code insert data in table
str = "insert into table values()";
SqlCommand cmd = new SqlCommand();
cmd.Connection="connection string";
cmd.CommandText = str;

and this code also insert data in table
string str = "insert into table values";
SqlDataAdapter adp = new SqlDataAdapter(str, "connection string");
DataSet ds = new DataSet();

so what is diffrent between them and which one to use is good?

[Edit]Pre tag added by Jibesh[/Edit]
Posted 15-Mar-13 6:33am
Updated 15-Mar-13 7:00am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use SqlCommand to execute INSTER/UPDATE/DELETE queries and SqlDataAdapter can be used for retrieving data from the database.

The second query you provided in your question is wrong. That query should be a SELECT query rather than INSERT
Member 9784436 15-Mar-13 12:50pm
ok sir but
String str = "update allocate set s_name='" + servr + "'where department='" + depa + "'";
ad = new SqlDataAdapter(str, Class1.con);
ds = new DataSet();

i have used in my project ans still it works, so what happing with me?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

When you are using Dataset, in fact you are saving the table information in ram. but when using command, you are filling the physical table which is stored in hard. so when you are using dataset, you can see more speed ;)
Member 9784436 16-Mar-13 0:09am
ok sir i got it
and thank you so much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100