Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Hey m having problem with value member of combobox ....

$
0
0
This is my code :-

                   Dim query As String

        Dim ds As New DataSet
        Dim dt As New DataTable
        Connect.con = Connect.openconnection
        query = "Select UserId,UserName From UserMaster"
        Dim da As New OdbcDataAdapter(query, Connect.con)
        da.Fill(ds, "UserMaster")
        dt = ds.Tables("UserMaster")
        Dim x As Integer
        x = 0
        Try

            For x = 0 To dt.Rows.Count - 1
                CbUsers.Items.Add(dt.Rows(x).Item(1))
                CbUsers.ValueMember = dt.Rows(x).Item(0)
            Next


        Catch ex As OdbcException
            MsgBox(ex.ToString)
        Finally
            Connect.closeconnection()
        End Try




M trying to get these values from database :-
UserId UserName
  1      admin

  3      admin2
  
  5      admin3


It fetches all the values from the database and bind to combobox easily but when i get the selected value from the combobox it resets the value members i.e. it shows id 1 at admin and 2 at admin2 and 3 at admin3 but the correct values in database is not like that :-O

Any one knows y it is happening ? Please help asap .......... :-O thanks in advance :-)

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>