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...
what did i miss? thanx in advance guys...VB Code:
Dim cn As New SqlConnection("integrated security=true;initial catalog=northwind") Dim cm As New SqlCommand() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn.Open() cm.Connection = cn cm.CommandType = CommandType.StoredProcedure With cm .Parameters.Clear() .CommandText = "GetCategoriesTable" Dim dr As SqlDataReader = .ExecuteReader While dr.Read ComboBox1.Items.Add(dr.GetValue(1)) End While dr.Close() End With End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged With cm .Parameters.Clear() .CommandText = "GetCategoriesRowOnName" .Parameters.Add("@Name", SqlDbType.NVarChar, 15).Direction = ParameterDirection.Input .Parameters("@Name").Value = ComboBox1.SelectedItem Dim dr As SqlDataReader = .ExecuteReader dr.Read() ComboBox1.Text = dr.GetValue(0) dr.Close() End With End Sub
--ayan




Reply With Quote