Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
VB
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedValue.ToString <> "" Then
            ComboBox1.SelectedIndex = 0
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\SHAKEE\AppData\Local\Temporary Projects\WindowsApplication1\sponsorship.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"


        Dim ds As New DataSet
        Dim adpt As New SqlDataAdapter
        cmd.CommandType = CommandType.Text
        cmd = New SqlCommand("SELECT name FROM child", con)
        adpt.SelectCommand = cmd
        cmd.Connection = con
        con.Open()
        adpt.Fill(ds, "child")
        con.Close()

        ComboBox1.DisplayMember = "countryname"
        ComboBox1.DataSource = ds.Tables(0).DefaultView



    End Sub
End Class

When I run this code I got a display in comboboxlist as system.data.datarowview

I need to display name.
How can I clear this error?
Posted
Updated 4-Jan-14 3:42am
v2

you are missing the DataTextField & DataValueField properties. As their names suggest, the first one correspond to the Text to show, and the second to the value one.
 
Share this answer
 
i have solved myself error is in

VB
ComboBox1.DisplayMember = "name"
 
Share this answer
 
Comments
Nelek 4-Jan-14 13:09pm    
I suppose the error was: "countryname" and the solution is "name"

If not... please use the "improve solution" widget and explain it better, it could help other people in the future.
Karthik_Mahalingam 7-Jan-14 1:44am    
please close this post by marking it as answer..
try this:

VB
With ComboBox1
   .DataSource=ds.tables(0).defaultView
   .DisplayMember="name"
   .Valuemember="name"
End With
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900