halu,

my friend and i got this problem a while ago. we don't know what wrong. it's about combo box with data reading. i don't know if my question meets our need here. sorry for that. hehe. cheers...

it's about retreiving Categories Table in the NorthWind and adding the CategoryName in the combo box. when name selected it supposed to display the CategoryID on the combo box text property. i don't know what's wrong... what event should we override? i tried this one...
VB Code:
  1. Dim cn As New SqlConnection("integrated security=true;initial catalog=northwind")
  2.     Dim cm As New SqlCommand()
  3.  
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         cn.Open()
  6.         cm.Connection = cn
  7.         cm.CommandType = CommandType.StoredProcedure
  8.         With cm
  9.             .Parameters.Clear()
  10.             .CommandText = "GetCategoriesTable"
  11.             Dim dr As SqlDataReader = .ExecuteReader
  12.             While dr.Read
  13.                 ComboBox1.Items.Add(dr.GetValue(1))
  14.             End While
  15.             dr.Close()
  16.         End With
  17.     End Sub
  18.  
  19.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  20.         With cm
  21.             .Parameters.Clear()
  22.             .CommandText = "GetCategoriesRowOnName"
  23.             .Parameters.Add("@Name", SqlDbType.NVarChar, 15).Direction = ParameterDirection.Input
  24.             .Parameters("@Name").Value = ComboBox1.SelectedItem
  25.             Dim dr As SqlDataReader = .ExecuteReader
  26.             dr.Read()
  27.             ComboBox1.Text = dr.GetValue(0)
  28.             dr.Close()
  29.         End With
  30.     End Sub
what did i miss? thanx in advance guys...

--ayan