I came across this question:
Which of the following are the valid method of command object?
The answer given here is : ExecuteQuery & ExecuteScalar

My doubt is why answer can not be ExecuteNonQuery and ExecuteScalar?

Hi,
I'm not sure exactly what your question is but this link will give you all the information on the SQL Command Object. The OLEDB Command object would have a similar syntax.

In vb.net section,
we write:
cmd.ExecuteNonQuery()
cmd.ExecuteScalar()

I was going through one of the quiz wherein they have given this question:
Which of the following are the valid method of command object?
The correct answer given was : ExecuteQuery & ExecuteScalar

My doubt is why the answer can not be ExecuteNonQuery?

ExecuteNonQuery..
1.It will not return any data.
2.It is used with insert and update.
3.It returns only the number of rows affected.

ExecuteScaler..
1.It returns only one value.
2.That value will the first column first row value.

ExecuteReader, ExecuteXMLReader etc.(usually referred to as Execute Query)
1.Its for command objects.
2.It returns the values given by database through select statement.

Did the questionon the quiz want you to get records or a value out of the Database? If so, that is why ExecuteNonQuery is not a valid answer.

Edited 3 Years Ago by G_Waddell: typo

The question is :
Which of the following are the valid method of command object?
They did not specify records or value.

Hi,

I'd question that then because ExecuteNonQuery is actually a valid method on the command object as is ExecuteScalar. The one I'd have questions about is ExecuteQuery. I've never used it or seen it being used and the only time I've heard it mentioned is as a catch all term for ExecuteReader, ExecuteXMLReader etc.

I asked same doubt as even I feel ExecuteNonQuery is a valid method

This article has been dead for over six months. Start a new discussion instead.