Hi,

In my windows application, I have 2 tabs in the tab control in this window form. A listbox will populate all store numbers first, then when user selects 1 store, the grid control will populate sales data.
However,
1. the following codes populate "System.Data" instead of real data in my listbox (in tab1) and I have to travel to tab2 and come back to tab1, then the listbox will be populated with store_num.
2. After this listbox populated store number, and I selected one store, the grid throws error on adpSales.selectedCommand=DBstrQ:
"An unhandled exception of tyep ' SYstem.NullReferenceException' occured. Object reference not set to an instance of an object.

Can someone point me out where did I do wrong? Thank you.

Dim daStoreNum As SqlDataAdapter
Dim dsStoreNum As New DataSet
conDWDb.Open()
daStoreNum = New SqlDataAdapter("SELECT DISTINCT Store_Num FROM Store_Table where store_mgr is not null order by store_num", conDWDb)
dsStoreNum = New DataSet("Store_Table")
daStoreNum.Fill(dsStoreNum, "StoreTable")
Try
Dim StoreList As DataTable = dsStoreNum.Tables("StoreTable")
dvStoreList = New DataView(dsStoreNum.Tables("StoreTable"))
lstStoreNum.DisplayMember = "Store_Num"
lstStoreNum.ValueMember = "Store_Num"
dvStoreList.RowFilter = strStoreFiltering
lstStoreNum.DataSource = dvStoreList
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub txtStoreNum_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStoreNum.TextChanged
strStoreFiltering = "Store_Num like '%" + txtStoreNum.Text + "%'"
dvStoreList.RowFilter = strStoreFiltering
dvStoreList.RowStateFilter = DataViewRowState.CurrentRows
End Sub
Private Sub lstStoreNum_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstStoreNum.SelectedIndexChanged

Dim DBstrQ As New SqlCommand("", conDWDb)
DBstrQ.CommandText = "SELECT Bus_Date AS Bus_Date, Store_Num , Z_Num_Transactions, Z_Net_Sales, Net_Food_Sales,Z_Meal_Pack_Cnt, Z_Meal_Pack_Amt,Z_Non_FoodA_Amt, Z_Non_FoodB_Amt,Z_Sales_Tax_Amt,Manual_Update_Ind FROM micros.Operations where store_num=@storenum"
adpSales.SelectCommand = DBstrQ
.....more codes
End Sub