How do I find the first record on my form from a combobox in Visual Basic 2010
This is well documented and easy to accomplish in Access, but how does one accomplish this in Visual Basic 2010 on a form designed in Visual Studio that is bound to a SQL Server database?
The idea is to create a combobox that holds 2 columns - a primary key value and a unique value such as a [Company Name] or a [Student Name]. The user would then find the appropriate record within the combobox and the code behind the combobox control would then perform a .findfirst method that would NOT filter out all other records, but would rather use selectedvalue primary key column value to move to the selected record.
I am currently getting into VS 2010 & revisiting VB having been programing in ACCESS & VBA for years. In the Access/VBA environment it is very common to have to find a given record on a given form using this method, but it would appear to be poorly documented if in fact not commonly used in the VB.NET/VS community.
Re: How do I find the first record on my form from a combobox in Visual Basic 2010
The best way to explain the problem is to demonstrate what I would normally do, so...
THE ACCESS Solution
================
I have an .MDB file that I have created and have uploaded it here.
This file will open up a students form as the initial form.
On the form, in the header you will find a ComboBox and a 2-Button option box.
If you choose a student from the ComboBox you will quickly locate the record associated to the student.
Also, if you choose to search by First Name instead of Surname, then you select a button below the search combobox that changes the rowsource of the combobox.
This is a very typical form that has to be designed as is efficient. As such it is an absolute requirement in all Visual Studio applications that I will need to develop.
The code behind the ComboBox can be viewed within access, but is pasted here for convenience:
Private Sub FindStudent_AfterUpdate()
'There are 2 possible methods that can be employed to locate a given record here by using VBA.
'Option 1: Using the FindRecord Option
'=======================================================================
' DoCmd.GoToControl "studentid"
' DoCmd.FindRecord Me.Combo21, acStart, , acDown, , acCurrent, True
'Option 2: Using the SearchRecord option (preferred)
DoCmd.SearchForRecord acDataForm, "frm_Students", acFirst, "studentID=" & CStr(Nz(Me.FindStudent.Value, ""))
End Sub
THEN...
I have done the same solution, but this time in VS 2010, with SQL Server as the DB.
I have uploaded the DB as a SQL Server .BAK backup file and the script to create the DB is contained in the StudentCourses.ZIP file - along with the entire VS solution.
I think that this will become a nice tutorial exercise, so I thought that it would be good if I was to upload both solutions here to be reviewed.
As you will see, the VS solution pops up a msgbox with the selectedvalue of the combobox.
I would like to use the BindingSource.Find method, but am uncertain of how to proceed.
Can someone please look at this solution and advise?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.