954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
 

Please move your thread to ASP.NET forum http://www.daniweb.com/forums/thread117180.html

reader.GetString(coulmnNumber); or
reader.GetInt32(columnNumber); based on your column data type and its number.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

Post moved

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You