Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 3rd, 2005, 12:49 PM   #1
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
DataReader or DataSet?

Ok, so I have this code, the problem is every time it executes and recurses it throws an exception because you can only have one DataReader open at a time, I do not want to go through the process of saving all the data to my local memory, it can be a lot of data which is annoyng, but I need to know how to perform multiple queries at once.

Would switch to a DataSet using the disconnected framework assist with that? Or is there another way to make DataReader allow for multiple queries without creating an indefinte number of connections (a very stupid approach in my opinion).

This is the code that I currently have:

		public productForm( mainForm parentForm )
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//set up the odbc connection reference
			this.MdiParent = parentForm;
			this.odbcConnection = parentForm.loginData.odbcConnection;

			try
			{
				//grab a list of product categories from the database.
				OdbcDataReader odbcResult;
				OdbcCommand odbcCommand = new OdbcCommand( "", this.odbcConnection );
				odbcCommand.CommandText = "SELECT categories.*, categories_description.* FROM categories INNER JOIN categories_description on categories.categories_id=categories_description.categories_id where categories.parent_id=0";
				
				odbcResult = odbcCommand.ExecuteReader( );
				while( odbcResult.Read( ))
				{
					ListBox newItem = new ListBox( );
					newItem.Text = odbcResult.GetString( 8 );
					this.categoryList.Items.Add( newItem );
					this._RecurseListCategories( odbcResult.GetInt32( 0 ).ToString( ), odbcResult.GetString( 8 ), 
						this.odbcConnection );
				}
			}

			catch ( OdbcException ex )
			{
				//database error, handle it now...
				for( int i = 0; i < ex.Errors.Count; i++ )
					MessageBox.Show( ex.Errors[i].Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
			}

			finally
			{
				//update our current catergory list no matter what
				this.categoryList.Update( );
			}
		}

		/// <summary>
		/// Recursively find category listings
		/// </summary>
		/// <param name="parentID">Current listing (will find children)</param>
		private void _RecurseListCategories( string parentID, string currentName, OdbcConnection connection )
		{
			OdbcDataReader odbcResult;
			OdbcCommand odbcCommand = new OdbcCommand( "", this.odbcConnection );
			odbcCommand.CommandText = "SELECT categories.*, categories_description.* FROM categories INNER JOIN categories_description on categories.categories_id=categories_description.categories_id where categories.parent_id=" + parentID;
				
			odbcResult = odbcCommand.ExecuteReader( );
			while( odbcResult.Read( ))
			{
				ListBox newItem = new ListBox( );
				newItem.Text = currentName + " : " + odbcResult.GetString( 8 );
				this.categoryList.Items.Add( newItem );
				this._RecurseListCategories( odbcResult.GetInt32( 0 ).ToString( ), 
					currentName + " : " + odbcResult.GetString( 8 ), this.odbcConnection );
			}
		}

Any help is greatly appreciated... thanks.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Apr 12th, 2005, 7:16 PM   #2
dark_omen
Hobbyist Programmer
 
Join Date: Dec 2004
Posts: 125
Rep Power: 4 dark_omen is on a distinguished road
Send a message via AIM to dark_omen
I don't know about this, but I think you can add another datareader like this:

OdbcCommand odbc_Second_Command = new OdbcCommand("");
odbc_Second_Command.CommandText = "SELECT"...;

I think that would work. But I was doing something similar in SQL that worked that way.
dark_omen is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC