ASP.NET with C# question

Results 1 to 2 of 2

Thread: ASP.NET with C# question

  1. #1
    Join Date
    Dec 1969

    Default ASP.NET with C# question

    I have a question regarding populating multiple drop down boxes from a single connection and command object. I have written the following code and it works, but I can&#039;t believe that there isn&#039;t a better way to do this than to close the connection and then reopen it. If anyone can tell me what I&#039;m doing wrong, I would be very grateful.<BR><BR>Thanks.<BR><BR>string strConnection = ConfigurationSettings.AppSettings["strSqlConn"];<BR>SqlConnection objConnection = new SqlConnection(strConnection);<BR>string strQuery = "select WBS from actionActionItem where WBS is not null order by WBS";<BR>SqlCommand objCommand = new SqlCommand(strQuery,objConnection);<BR> <BR>//populate WBS box with WBS numbers from actionActionItem<BR>objConnection.Open();<BR>ddlWB S.DataSource = objCommand.ExecuteReader();<BR>ddlWBS.DataTextFiel d = "WBS";<BR>ddlWBS.DataBind();<BR>objCommand.Connect ion.Close();<BR> <BR>//populate developer box with names<BR>objConnection.Open();<BR>strQuery = "select MemberName, TeamMemberID from adminTeamMember where (ReportsToTeamMemberID is not null and EndDate is null) or TeamMemberID = 5 order by MemberName";<BR>objCommand.CommandText = strQuery;<BR>ddlDeveloperName.DataSource = objCommand.ExecuteReader();<BR>ddlDeveloperName.Da taTextField = "MemberName";<BR>ddlDeveloperName.DataValueFie ld = "TeamMemberID";<BR>ddlDeveloperName.DataBind();<BR > <BR>objConnection.Close();

  2. #2
    Join Date
    Dec 1969

    Default RE: ASP.NET with C# question

    Yeah, that&#039;s pretty much what I do is just change the commandtext property of my command object each time. BUT, I only close the connection when I&#039;m done with everything. I don&#039;t close and reopen all the time and I&#039;ve never had a problem with that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts