Solved

use combo box to read data in SQL Server 2005 db

Posted on 2007-11-14
4
1,227 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now