Say i execute the following sql statement: SELECT employee_name, employee_age FROM employees WHERE employee_id = 1 Im using the following code to display the employee name (C#) myReader = cmd.ExecuteReader(); while (myReader.Read()) { string this_name = myReader.GetValue(0).ToString(); Response.Write(this_name); } I know for sure just one record is going to be retrieved. How do i display the employee_name without having to loop through the reader?
Can you try cmd.ExecuteScalar()? it will return one value as an object, and you can convert to a string.
Sorry my mind wasnt working i just had to change the 'while' to 'if' as follows: if(myReader.Read()) { string this_name = myReader.GetValue(0).ToString(); Response.Write(this_name); }