I know I can read data from database using these three terms but can Any one please guide me properly when to use ExecuteScalar, ExecuteReader and DataSet??
I know I can read data from database using these three terms but can
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ExecuteScalar: use it to execute any user defined function or the stored procedures, that usually has a scalar return value. i.e returns only one value. However, it can also be used with other queries or stored procedures, but in this case it returns only the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.ExecuteReader: use it for the usual queries that you pose to the database or with the stored procedure. TheCommendTextproperty is what determines whether it is a query or a stored procedure name. It sends theCommandTextto the Connection and builds aSqlDataReaderthat returns a set.Data set is a different thing than the
ExecuteReaderandExecuteScalarit represents an in-memory cache of data that are usually coming from the database.