Solved

use combo box to read data in SQL Server 2005 db

Posted on 2007-11-14
4
1,234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 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