Results 1 to 3 of 3

Thread: erros in my listbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    24

    erros in my listbox

    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

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    24

    Re: erros in my listbox

    never mind, I just recreated the form and droped the existing one, it works.....

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: erros in my listbox

    Please resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width