Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27285

VS 2010 Databound comboboxes repeating data

$
0
0
I have several comboboxes on various tabs which I want to load from the database to give a simple list of student names and group names.
The problem is, if I have 2 comboboxes for the student names, the data is repeated twice in both comboboxes. And if I have 2 comboboxes for the Groups, the data is repeated 5 times in all the comboboxes.
The code I have is below.
vb.net Code:
  1. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  2.         Me.Visible = True
  3.         Dim SQL As String = "SELECT stID, stName FROM tblStudent ORDER BY stName"
  4.         Dim Val As String = "stID"
  5.         Dim disp As String = "stName"
  6.         FillCombo(SQL, cboName, Val, disp, "Student")
  7.         FillCombo(SQL, cboStudentName, Val, disp, "Student")
  8.         SQL = "SELECT grID, grName FROM tblGroup ORDER BY grName"
  9.         Val = "grID"
  10.         disp = "grName"
  11.         FillCombo(SQL, cboStudentGroup, Val, disp, "Group")
  12.         FillCombo(SQL, cboRegistersGroup, Val, disp, "Group")
  13.         FillCombo(SQL, cboReportsGroup, Val, disp, "Group")
  14.         FillCombo(SQL, cboAttendanceGroup, Val, disp, "Group")
  15.         FillCombo(SQL, cboMaintGroupName, Val, disp, "Group")
  16.     End Sub
  17.  
  18.     Private Sub FillCombo(ByVal SQL As String, ByVal CBO As ComboBox, ByVal val As String, ByVal disp As String, ByVal tblName As String)
  19.         dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0"
  20.         dbSource = "Data Source=" & Application.StartupPath & "\Student.mdb"
  21.         Conn.ConnectionString = dbProvider & ";" & dbSource
  22.         Conn.Open()
  23.         da = New OleDb.OleDbDataAdapter(SQL, Conn)
  24.         da.Fill(ds, tblName)
  25.         Conn.Close()
  26.         CBO.DataSource = ds.Tables(tblName)
  27.         CBO.ValueMember = val
  28.         CBO.DisplayMember = disp
  29.     End Sub
Why is it repeating the data the same number of times as there are comboboxes and how do I solve it?

Viewing all articles
Browse latest Browse all 27285

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>