Abhilash Nagar
asked on
SQLDataReader giving only one field
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( "@StudentI d", SqlDbType.Int);
getStudent.Parameters["@St udentId"]. 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.
}
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(
getStudent.Parameters["@St
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.
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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.