Results 1 to 13 of 13

Thread: Code Throwing errors

Hybrid View

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

    Re: Code Throwing errors

    If you've data-bound your ListBox then each item is a DataRowView, not a String. This means that you're seting the Value property of you parameter to a DataRowView. If you want the actual string displayed in the ListBox that corresponds to the SelectedItem you would need to use this:
    VB Code:
    1. da.SelectCommand.Parameters.Add("@Division", ListBox1.GetItemText(ListBox1.SelectedItem))
    If you aren't using the ValueMember for any other purpose, you could set the ValueMember to the same column as the DisplayMember and just use the SelectedValue instead:
    VB Code:
    1. da.SelectCommand.Parameters.Add("@Division", ListBox1.SelectedValue)
    Also, the ListViewItemCollection.Add method returns a ListViewItem object, so you should use that to add your subitems:
    VB Code:
    1. For Each dr In dt.Rows
    2.                     Dim newItem As ListViewItem = ListView1.Items.Add(dr("license_id"), dr("product_name"))
    3.                     newItem.SubItems.Add(dr("company_name"))
    4.                     newItem.SubItems.Add(dr("po_number"))
    5.                     newItem.SubItems.Add(dr("date"))
    6.                     newItem.SubItems.Add(dr("users_licenses"))
    7.                 Next
    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

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: Code Throwing errors

    Well its working now except its throwing a new error:


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