ExecuteNonQuery or using a dataset?
-
When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!
-
When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!
DataSet
is for when you want to many more things than that , if you want one time access , one record returned useExecuteNonQuery
. UseDataset
when you want disconnected many insert/update/delete/read from your database. Mazy "Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland -
When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!
:confused:
ExecuteNonQuery
will not return any data. :confused: How can you execute a query withExecuteNonQuery
? That is for maintenance or updata/insert/delete tasks when you don't need a result back from the database.ExecuteDataReader
orExecuteScalar
do return data. The former returns a Data Reader object which you can use to access the records, and the latter returns a single value (If your query generates more than one value the single value returned will be the first field on the first row) If you are using a dataset you can disconnect from the data source - This is useful for mobile applications, for instance. With a dataset you copy the data into your application and work on the copy (this increases the memory overhead). A rule-of-thumb that I use is that if the data is a one-time use or I will be constantly connected to the database I use a data reader. If I am going to disconnect from the database I use a dataset. In general I prefer to use a data reader because the memory overhead is less and often it is faster to send a query to the database than filter an existing dataset because the database is designed to be queried efficiently, a dataset it not. Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
-
:confused:
ExecuteNonQuery
will not return any data. :confused: How can you execute a query withExecuteNonQuery
? That is for maintenance or updata/insert/delete tasks when you don't need a result back from the database.ExecuteDataReader
orExecuteScalar
do return data. The former returns a Data Reader object which you can use to access the records, and the latter returns a single value (If your query generates more than one value the single value returned will be the first field on the first row) If you are using a dataset you can disconnect from the data source - This is useful for mobile applications, for instance. With a dataset you copy the data into your application and work on the copy (this increases the memory overhead). A rule-of-thumb that I use is that if the data is a one-time use or I will be constantly connected to the database I use a data reader. If I am going to disconnect from the database I use a dataset. In general I prefer to use a data reader because the memory overhead is less and often it is faster to send a query to the database than filter an existing dataset because the database is designed to be queried efficiently, a dataset it not. Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Thanks for your particular answer:) It helps me a lot:)