Inserting data from dropdown menu into sql db in vb .net

Posted on 2007-10-02
Last Modified: 2013-11-26
I have an vb .net page that has a dropdown menu populated by a SQL table. The table has two fields, one for IDs and the other the ID's descriptions. The table has 12 rows. I've configured the dropdown menu to be populated like so:
            'Populate the drop down menu
            DropDownList3.DataSource = ds_1
            DropDownList3.DataSource = ds_1.Tables(0)
            DropDownList3.DataTextField = ds_1.Tables(0).Columns("ProfessionalType").ColumnName.ToString()
            DropDownList3.DataValueField = ds_1.Tables(0).Columns("ProfessionalTypeId").ColumnName.ToString()

However, when I select any ID description from the dropdown menu, the value entered to my custom table is always value 1 which the first value in the ID column.

How can I get the correct ID value inserted into my table when I select any of the ID description from the dropdown menu.

For example,
ID     idtype
1     Sam
2     Joe
3    Jack

When I select Jack from the dropdown menu and run the below command in vb .net
            AddCardioCom_Usr = "EXEC sp_AddCardioCom_Usr '" & TextBox3.Text & "', '" & TextBox4.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & DropDownList2.SelectedValue & "','" & DropDownList3.SelectedValue & "'"
            Dim dbAddCardioCom_Usr As SqlCommand = New SqlCommand(AddCardioCom_Usr, myconnection_1)

the value inserted in the backend is always 1.

Any suggestions!?
Question by:redouard
    LVL 2

    Accepted Solution

    Have you looked at the source code to see what the drop down values look like and see if they are indeed getting (1,2,3)?

    Do something like this to populate the box:

    DropDownList3.DataSource = ds_1.Tables(0)
    DropDownList3.DataTextField = "ProfessionalType
    DropDownList3.DataValueField = "ProfessionalTypeId"
    LVL 8

    Expert Comment

    make sure u load ur drowndownlist inside of
    if  not ispostback

    Author Comment

    I'm sure that the dropdown menu is getting the correct ID values. The only value that its getting the is the first row values which is 1. I select Jack which has an ID value of 3 but in the table after the insert the value is 1 and always 1. I feel that the its not searching the table correctly to get the select ID number. Am I doing any wrong with my code. I made the changes that you suggested. I encountered the same behavior.
    LVL 2

    Expert Comment

    Are you just using a simple submit type button?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now