SQLDataReader giving only one field

Abhilash Nagar
Abhilash Nagar used Ask the Experts™
on
Hello,
Anything incorrect below as i am getting only single field rather then 3 in the datareader. I am just getting StudentID field value only.

SqlCommand getStudent = InitiateDatabaseCommand();

            getStudent.Parameters.Add("@StudentId", SqlDbType.Int);
            getStudent.Parameters["@StudentId"].Value = 1;
            getStudent.CommandText = "Select * From Student  r where r.StudentID=@StudentId AND r.Name like '%R%'";

            SqlDataReader dr = comm.ExecuteReader();

        while (dr.Read()){

           //filling the studentinfo data model object here.
        }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
//filling the studentinfo data model object here.

You omitted the most significant piece of information from your question. Could you please demonstrate what is it that is being written where you have mentioned the above text?

Also, please show us the structure of the Student table.
.NET Developer
Commented:
Thanks for the response. some Syntax was the issue. So i did it but really thanks for the response.
Abhilash Nagar.NET Developer

Author

Commented:
I was referring a command object which was incorrect.

Correct command object was SqlCommand comm

I was referring to the SqlCommand testcomm which was running execute scalar.

Thanks for all the responses. Really appreciate your time.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial