Tuesday, March 22, 2005

SqlDataReader is readonly now I understand !

I was trying to return a parameter from a Stored procedure and I was performing this using the following lines of code:

SqlDataReader reader = myCommand.ExecuteReader();

// after few lines

int myID = Convert.ToInt32(myCommand.Parameters["@myID"].Value);

@myID was the output parameter added to the myCommand object.

Guess what ! myID always returned zero. Then I found out that you cannot return a parameter from the stored procedure if you are using SqlDataReader.

Later I used this code:

myCommand.ExecuteNonQuery();

and it worked like a charm.

:)

No comments: