Solved

use combo box to read data in SQL Server 2005 db

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

896 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

15 Experts available now in Live!

Get 1:1 Help Now