By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

MySQL DataReader, Arrays, and Combo boxes....

P: 2
Hi,

I have been working on this problem for about 5 days now, and I cant find anything on the web to help me.

Ill tell you the end result, first... My combo box is listing the same data over and over. the data is pulling from an arraylist. the arraylist is populated from a MySQL database table with three columns. I want the second column of the arraylist to populate the combo box.
example: the combo box has 4 selections (funny.. exactly how many rows are in the test db table...)
Township Docs
Township Docs
Township Docs
Township Docs

The list should be...
Township Docs
HR Docs
Police Docs
AP Docs


the function I wrote to query the database (currently it has three columns and 4 rows) is below:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetDocumentFamilies(ByVal dataBase As String) As ArrayList
  2.  
  3.         Dim objConnection As New MySqlConnection(_ConnectionString)
  4.         Dim objCommand As New MySqlCommand
  5.         Dim returnArrayList As New ArrayList
  6.  
  7.         objCommand.Connection = objConnection
  8.         objCommand.CommandText = "select doc_family_id, doc_family_name from " & dataBase & ".doc_family_table"
  9.  
  10.         objConnection.Open()
  11.  
  12.         Dim myreader As MySqlDataReader = objCommand.ExecuteReader()
  13.  
  14.  
  15.         While myreader.Read
  16.             returnArrayList.Add(myreader)
  17.         End While
  18.  
  19.         Return returnArrayList
  20.  
  21.         myreader.Close()
  22.         objConnection.Close()
  23.  
  24.  
  25.     End Function
  26.  
Theory 1 is that the datareader is just populating the same row of data 4 times? I cant be sure.

When the form with the combo box loads, the following code is executed:
Expand|Select|Wrap|Line Numbers
  1. Private Sub frmEditDocumentTypes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         Dim myini As New msiINI
  3.         Dim mydb As New msiDB(myini.DataSource, myini.UserId, myini.Pwd)
  4.         Dim myarray As New ArrayList
  5.         Dim mycount As Integer
  6.  
  7.  
  8.  
  9.  
  10.         myarray = mydb.GetDocumentFamilies(myini.DBase)
  11.  
  12.         For mycount = 0 To myarray.Count - 1
  13.             Me.cboDocumentFamily.Items.Add(myarray(mycount)(1))
  14.  
  15.         Next mycount
  16.  
theory 2 is that I dont quite understand how arraylists work and the (myarray(mycount)(1)) code is completely off base.



If there is anyone out there that help save whats left of my sanity, I would be greatly appreciative!

thanks,

Liquid-G
Nov 7 '07 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi Liquid-G.

I think the problem is in the way you fetch the data from your ArrayList.
Try something like:
Expand|Select|Wrap|Line Numbers
  1. myarray(mycount, 1)
  2.  
Also, in your first code snipped, you should close your reader and the connection before you return the function's value. Any code after the return keyword will not be executed.
Nov 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.