Question Combobox and Textbox not showing data.

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi everyone,

Im going nuts with vb because I've been trying to get some data to show in my combo box and my text box, could someone please help me out here.

I have a database and inside that database I have a table, the table has various fields e.g name, address, telephone number. What I'm trying to do is show the 'Name' in the combo box and the 'address' in the text box. So far I have the following:

VB.NET:
'This is at the top 
Imports ss = System.Data.SqlClient 

'This is above the form load event: 

   Dim cn As New System.Data.OleDb.OleDbConnection 
    Dim cm As New System.Data.OleDb.OleDbCommand 
    Dim rd As System.Data.OleDb.OleDbDataReader 

'And this is in the form load event: 

    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb" 
        Try 
            cn.Open() 
        Catch ex As Exception 
            MessageBox.Show(ex.Message) 
        End Try 
        cmbbyname.Items.Clear() 
        cm.Connection = cn 
        cm.CommandText = "select * from people" 
        rd = cm.ExecuteReader() 
        While (rd.Read) 
            cmbbyname.Items.Add(rd("Name")) 
        End While 
        rd.Close() 
        If cmbbyname.Items.Count > 0 Then 
            cmbbyname.SelectedIndex = 0 
        End If 
        Try 
            Dim adp As New Data.OleDb.OleDbDataAdapter 
            Dim ds As New DataSet 
            Dim dv As New DataView 
            adp.SelectCommand = cm 
            adp.Fill(ds, "dataset") 
            dv.Table = ds.Tables(0) 
            dv.Sort = "name" 
        Catch ex As Exception 
            MessageBox.Show(ex.Message) 
        Finally 
            cn.Close() 
        End Try

I have the combo box part working so when the form loads I can see the Name in the combobox, but im struggling to show the address in the textbox. Ive read a bit about databiding but I don't like the sound of it as I would prefer to code everything rather than letting vb connect to the db..

Please help me. thanks
 
Back
Top