title: Getting Dropdownlist selected value in vb.net
body: <p>I am trying to set user account for my system. I have two tables (User and Staff)</p>
  
  <p>And this is the interface for setting up user
  <a href="https://i.stack.imgur.com/mNp7Y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mNp7Y.jpg" alt="enter image description here"></a></p>
  
  <p>the name dropdownlist  need to be bound to staff table where I can display a list of staff members. When I insert these data to the user table I need to convert the selected staff name into its ID. </p>
  
  <p>I'm really weak in programming and if possible help me with this.
  this is the code I am using</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnUserAdd.Click
      If ValidData() Then
          Try
              cmd.Connection = con
              con.Open()
              sel_id = Convert.ToString(cmbStaffName.SelectedValue)
              cmd.CommandType = System.Data.CommandType.Text
              cmd.CommandText = "Insert Into dbo.[User] (User_ID,Employee_ID,User_Name,Password,User_Level) values ('" &amp; txtBoxUserID.Text &amp; "','" &amp; sel_id &amp; "','" &amp; txtBoxUserName.Text &amp; "', '" &amp; txtBoxPassword.Text &amp; "','" &amp; ComboBox1.Text &amp; "')"
              cmd.ExecuteNonQuery()
              MsgBox("Succesfully Added", MsgBoxStyle.Information, "add")
  
          Catch ex As Exception
              MessageBox.Show(ex.Message)
  
          End Try
          con.Close()
      End If
  
      If Not ValidData() Then
          Exit Sub
      End If
  End Sub
  
  
  
  Private Sub btnUserUpdate_Click(sender As Object, e As EventArgs) Handles btnUserUpdate.Click
  
  End Sub
  
  Private Sub Setup_User_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      'TODO: This line of code loads data into the 'MyHotelManagementSystemDataSet19.Staff' table. You can move, or remove it, as needed.
      Me.StaffTableAdapter1.Fill(Me.MyHotelManagementSystemDataSet19.Staff)
      'TODO: This line of code loads data into the 'MyHotelManagementSystemDataSet18.Staff' table. You can move, or remove it, as needed.
      Me.User_TypeTableAdapter.Fill(Me.MyHotelManagementSystemDataSet17.User_Type)
  
  End Sub
  
  Private Sub cmbStaffName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbStaffName.SelectedIndexChanged
  
      Try
          con.Open()
          ds = New DataSet()
          cmd = New SqlCommand("select * from Staff", con)
          Adapter = New SqlDataAdapter(cmd)
          adapter.Fill(ds)
          cmbStaffName.DataSource = StaffBindingSource1
          cmbStaffName.DisplayMember = "Name"
          cmbStaffName.ValueMember = "Employee_ID"
  
      Catch ex As Exception
      Finally
          con.Close()
      End Try
  End Sub
  </code></pre>