Is this a good way ?

Hi, I am developing a vb.net application which access a SQLServer DB's table to Edit some fields based on the user selection. For Example:-

Say the Table is:-

Employee
--EmployeeID
--EmployeeName
--EmployeeSalary

To edit this table in a form i did this steps:-
1. In the form LOAD event i read whole table (only ID and Name) and put names in a combo box and ID in a HIDDEN listbox to track the User selection.- like:-

' conn done here
Dim cmd As New SQLCommand("SELECT EmployeeID, EmployeeName FROM Employee",conn)
Dim rdr As SQLDataReader=cmd.ExcuteReader()
While(rdr.Read())
Me.lstEmployeeID.Items.Add(rdr.getValue(0))
Me.cmbEmployeeNames.Items.Add(rdr.getString(1))
End While
rdr.Close()
' closing stuffs

And When the user select an item in comboBox i tracked the ID by(in the combo's change event) :
eID=Me.lstEmployeeID.Items.Item(Me.cmbEmployeenames.SelectedIndex)

and i built the query to read the salary.

So My question is :-
1. Is this the best way to track ID in this situation or any other way is there
2. If the database contails 20,000+ records then to populate combo in the LOAD event it will take massive time. How to overcome OR any other way to edit

Thnx In advance.


Answer this question

Is this a good way ?

  • Ralph Kester Caparros

    I would create a function that will return a collection of ID/Name (in a class). That way your database will be seperate from your UI. This way it's cleaner and anytime you need to get that list you just need to call the function.

    I would suggest to create a search screen, showing maybe 100 employee per page and have the option to search for an employee (ex: by name). After this it's easy to just click on the one you want and edit it.

    If you need to display a list of employee to insert in an other table. You can ahve an empty label with a button beside it that will open a Employee Search window, when cliked, the label is filled with the information of the employee selected.

  • Is this a good way ?