Solved

use combo box to read data in SQL Server 2005 db

Posted on 2007-11-14
4
1,230 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 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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