Hi people, I was hoping someone could offer me some help please.
I have a database and vb.net as the front end. On my form I have a combobox and a textbox. What I want to do is show the name field in the combbobox and the address field in the textbox. So far I have the combobox working perfectly but I'm stuggling to get the textbox to connect with the combobox and the database.
My coding so far is:
?? = I dont know what to put there.Code:Imports ss = System.Data.SqlClient Dim cn As New System.Data.OleDb.OleDbConnection Dim cm As New System.Data.OleDb.OleDbCommand Dim rd As System.Data.OleDb.OleDbDataReader 'Following is under 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() txtbyname.Clear() cm.Connection = cn cm.CommandText = "select * from people" rd = cm.ExecuteReader() While (rd.Read) cmbbyname.Items.Add(rd("Name")) ' txtbyname.Text = cn.ExecuteScalar.ToString("Address"))?? 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
Any help is really appeciated, please help me as I'm really struggling.




Reply With Quote