Jump to content
Compatible Support Forums
Sign in to follow this  
Atreyu

C# Programmers

Recommended Posts

Anybody on here good with C#? I'm working on a project here at home and I'm a bit stuck. It would be cool to have somebody to bounce ideas off of. Any takers?

 

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.

Share this post


Link to post

Thanks for the reply.

 

I know about the theory and how it's done in VB and C++, but I've not done these things in C#. For example, I'm looking for an answer to the question, "Can I pass/receive a datareader object to/from a function?". I'm assuming the answer is yes, but it may not be. The reason I ask that is if I create a class, for example, that handles DB queries I'll need to pass the results back to the calling logic. Either that, or pass objects requiring the data into the classes, which I'd really rather not do. Perhaps if I can't pass datareaders, I could dump a datareader into an array and pass that back. Hmmmm.

 

Basically I was hoping in addition to finding some answer to this, to find somebody I could add to my IM buddy list to ask questions of, when the need arises.

 

And yes, I've been looking all around. I've found some good info and it's slowly leading me to my answers. Just thought I'd try my luck here as well.

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×