Basically what I'm trying to do right now is use one method for all database transactions. In this particular app it's all read-only so I'm using a datareader. However, I'm not sure how to (or if it's possible) to pass a data reader to a method and have it returned filled. I WAS able to do it with a dataset since it's disconnected, but it's too much overhead for my purpose.
I would like to avoid repeating code over and over in many different methods and events if possible. If anybody has some examples of this it would be greatly appreciated.
Currently here's what I'm working on. I don't like it, but it's as close to the above as I've been able to get:
Code:
private void Page_Load(object sender, System.EventArgs ea) { if(!this.IsPostBack) { SqlDataReader drResults; string strConn; string strSP; strConn = "********" //drResults.Clear(); try { using(SqlConnection objConn = new SqlConnection(strConn)) { objConn.Open(); //Fill Genre ComboBox strSP = "sp_Genres"; SqlCommand cmdSQL = new SqlCommand(strSP, objConn); drResults = cmdSQL.ExecuteReader(); cbxGenre.DataSource= drResults; cbxGenre.DataTextField = "fldGenre"; cbxGenre.DataBind(); //Fill CD ComboBox if (rdSwitch.Checked==true) { strSP = "sp_CDNamesPG"; } else { strSP = "sp_CDNamesAll"; } SqlCommand cmdSQL = new SqlCommand(strSP, objConn); drResults = cmdSQL.ExecuteReader(); cbxCDName.DataSource= drResults; cbxCDName.DataTextField = "fldCDName"; cbxCDName.DataBind(); objConn.Close(); } } catch(Exception eException) { txtTitleSearch.Text = "There were problems. " + eException; } } }
The remaining problem with this is that with one of my combo boxes, if I select a different radio button, it needs to repopulate with different data. In this scenario all controls will repopulate, even though only one is needed. I could use some input.

Help










