Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

use combo box to read data in SQL Server 2005 db

Posted on 2007-11-14
4
Medium Priority
?
1,241 Views
Last Modified: 2013-11-26
I could really use a lot of help on how to code a combo box in Microsoft Visual Studio if I am connected to SQL Server 2005 db.
I'm not even sure where to begin.  I'm connected to the db and I can move previous and next and all of the fields on the form change the way I would expect.  But I want to be able to select a FileNo from the combo box and have it fill the form with the correct data.  

I have tried creating the following view in SQLServer 2005 but it won't even compile...

SELECT     FileNo, SSN, FirstName, MiddleName, LastName, Dependants
FROM         dbo.tblClientInfo
WHERE     (FileNo = @FileNo)

If I take off the Where clause (just to get something to work) I can save it.  So I tired using the followng   code in the SelectedIndexChanged property of my cboFileNo combo box.  It complies but when I select a file number from the dropdown menu I get the errors
Relax or turn off constraints in your DataSets.
Clear datasets before loading them from view state.
Code in the SelectedIndexChanged property:
   Private Sub LoadByFileNo(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.VuLkUpFileNoTableAdapter.Fill(Me.ServicesDataSet.vuLkUpFileNo)
    End Sub

I don't even know if I'm on the right track.  I have viewed many "how to" videos on VB.net but none of them have an example using a dropdown menu the way I want.

I could really use some detailed help.  A link to detailed instructions on how to create a combo box would also work.
Thanks in advance!
0
Comment
Question by:BobRosas
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
BryanMI earned 1000 total points
ID: 20284798
I have done this with a databound combo box.  You should be able to go into the properties of the combobox and configure it as a databound control and query for the values to load.

In the design mode of your form you should see it when the combo box is selected.  It will let you create the query you desire in the control specification.

Regarding your view, views don't take parameters.  That's only doable in stored procedures.  If you know the values you want to restrict on, you can enter them in a where clause.  At runtime if you want to filter, you have to put a where on the end of your view.

For example:  SELECT A, B, C FROM vwMyView WHERE A = 1234
0
 

Author Comment

by:BobRosas
ID: 20285610
Thank you for responding.  
I went to the properties window of the combo box and tried creating the following query because it used the @parameter in an example and it says qry not view.
SELECT     FileNo, SSN, FirstName, MiddleName, LastName, Dependants
FROM         dbo.tblClientInfo
WHERE     (FileNo = @cboFileNo)
However I get the same messages.
If parameters are only doable in a stored procedure could you help me with the code I'd need in a stored procedure?  And how I would use it with my combo box?
Thanks!
0
 

Author Comment

by:BobRosas
ID: 20290375
Bryan,
I changed the datasource of the combo box to my table and the selected value to my view and everything seems to be fine.  That just shows how new I am to all this.  I thought I would need a class and procedures and I didn't know how to link it all.  I was trying to do to much.
Thanks for your input.  
0
 

Expert Comment

by:logoncom
ID: 21805317
I am trying to do this now but even after reading above I can't get it to work.  I want to fill a combobox with a paramaterized sql query.  The paramater will be chosen by a different combobox.  I've created a query using the combobox and tried a stored procedure... problem is, I dont understand how I set the paramater to the selected value.  
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question