Populating a dropdown with data from an SqlServer stored procedure
Hi, I am rather new to programming. I have a stored procedure that simply reads a 'CourseCode' from a Course table, the stored procedure code is as follows:
--------------------------------------------
ALTER PROCEDURE dbo.Courses
AS
SELECT CourseCode
FROM Course
RETURN
---------------------------------------------
I have C# code in the code behind page to try and popuate a dropdownlist with a list of CourseCodes, it is as follows:
public void getCourseDropDown()
{
try
{
command = new SqlCommand("Courses", myConnection);
myConnection.Open();
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
DD_Course_uploadBrief.Items.Add(new ListItem(reader("CourseID".ToString())));
}
reader.Close();
}
catch (Exception objException)
{
//Display the exception message
string strError = objException.Message;
if ((objException.InnerException != null))
{
strError += objException.InnerException.Message;
}
}
finally
{
// Clean Up
reader = null;
}
}
------------------------------------------------------------------------------
When I build the asp.net website application I get the following error:
'reader is a field but is used like a method'
I would be very grateful for any help you all may have,
thanks in advance :)
Elmo_loves_you
Junior Poster in Training
85 posts since Mar 2008
Reputation Points: 30
Solved Threads: 0
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902