User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,045 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,256 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 478 | Replies: 2
Reply
Join Date: Mar 2008
Posts: 37
Reputation: Elmo_loves_you is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Elmo_loves_you Elmo_loves_you is offline Offline
Light Poster

populating a dropdown with data from an SqlServer stored procedure

  #1  
Apr 3rd, 2008
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
Last edited by Elmo_loves_you : Apr 3rd, 2008 at 5:14 am. Reason: Trying to wrap code in tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 759
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 4
Solved Threads: 57
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: populating a dropdown with data from an SqlServer stored procedure

  #2  
Apr 3rd, 2008
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.
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,143
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 258
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: populating a dropdown with data from an SqlServer stored procedure

  #3  
Apr 3rd, 2008
Post moved
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC