Click here to Skip to main content
11,920,772 members (59,275 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C# ASP.NET C#4.0
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 7:33am
Edited 15-Mar-13 8: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 Wink | ;)
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
0 OriginalGriff 548
1 Dave Kreskowiak 245
2 phil.o 170
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2015
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