简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM