Trying to load up combo box values once (at login screen) vb.net
I have a few combo boxes that need to be loaded up once and displayed multiple times (whenever the main form is opened) The reason for this is because it's taking about 10 seconds for the form to load each time it's opened due to unnecessary re-querying.
Here is an example of what I have as a combo box source and what I've done.
I've put the query, connection, etc... in a module and call it on the login form - i don't get any errors but the data does 开发者_运维百科not load into the combos.
'In Module
sql = "SELECT DIR_ID, DIR_NM FROM LTC_FBS_DIR ORDER BY DIR_NM ASC"
RConStr = String.Format(RConStrFormat, LoginForm.txtUser.Text, LoginForm.txtPass.Text)
'using instead of dim connemp
Dim connemp4 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(RConStr)
connemp4.Open()
Dim datemp4 As OleDbDataAdapter = New OleDbDataAdapter(sql, connemp4)
datemp4.Fill(ds, "Dir")
'Form Load event
Dim tbl4 As DataTable = ds.Tables("Dir")
DBS_DIRECTORComboBox.DisplayMember = "DIR_NM"
DBS_DIRECTORComboBox.ValueMember = "DIR_ID"
DBS_DIRECTORComboBox.DataSource = tbl4
Your code looks fine; Make sure there is some data in dataset and/or Try skipping table mappings, I mean change your code lines.
Replace this line
datemp4.Fill(ds, "Dir")
With this line
datemp4.Fill(ds)
Also replace this line
//' in Form Load event
Dim tbl4 As DataTable = ds.Tables("Dir")
With this one
Dim tbl4 As DataTable = ds.Tables(0)
精彩评论