Click here to Skip to main content
Rate this: bad
good
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;
cmd.ExecuteNonQuery();
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();
adp.Fill(ds);
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
Jibesh16.6K
v2
Rate this: bad
good
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
  Permalink  
Comments
Member 9784436 at 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();
ad.Fill(ds);
 
i have used in my project ans still it works, so what happing with me?
Rate this: bad
good
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 | ;)
  Permalink  
Comments
Member 9784436 at 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 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
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