Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this code insert data in table
C#
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
C#
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
Updated 15-Mar-13 7:00am
v2

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 ;)
 
Share this answer
 
Comments
Member 9784436 16-Mar-13 0:09am    
ok sir i got it
and thank you so much.
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
 
Share this answer
 
Comments
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();
ad.Fill(ds);

i have used in my project ans still it works, so what happing with me?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900