troubleshooting Question

Why DataBind() is not Working but Read() do?

Avatar of JaimeJegonia
JaimeJegoniaFlag for United States of America asked on
C#
7 Comments1 Solution323 ViewsLast Modified:
Dear Experts,

I just want to understand or to be enlightened why Databind() is not working in this procedure?

While using  this instead of DataBind():
        while ( DR.Read() )
            {
         DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );             
                                }

It works.


Thanks,


Jimi J.

********************* CODES *************************

// Create Instance of Connection and Command Object
                              OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["DatabaseCRTP1"]);

                              OleDbCommand myCommand = new OleDbCommand("QSRSBals", myConnection);

                              // Mark the Command as a SPROC
                              myCommand.CommandType = CommandType.StoredProcedure;

                              // Execute the command
                              DropDown.Items.Clear();
                              myConnection.Open();
                              
                              DropDown.DataTextField = "Detail";
                              DropDown.DataValueField = "SRSDetID";
                        
                              OleDbDataReader DR = myCommand.ExecuteReader( CommandBehavior.CloseConnection );
                              DropDown.DataSource = DR;
                               
                                        DropDown.DataBind();

                              //while ( DR.Read() )
                              //{
                              //      DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
                        
                              //}

                              DropDown.Items.Insert(0,"-Pick-");
                              DropDown.SelectedIndex = 0;
                              
                              DR.Close();
                              myConnection.Close();




Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros