Results 1 to 13 of 13

Thread: Listbox on windows form

Threaded View

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Listbox on windows form

    I am being driven insane by this stupid little problem.
    I use the following code to bind a list of tables from my database to a listbox control on a windows form :
    Code:
     
    Dim strConnectionString
            Dim dtTables As New DataTable
            strConnectionString = "data source=server;database=dbname;user id=doggy;password=poopoo"
            'Create connection object
            Dim Connect As New SqlConnection(strConnectionString)
            Dim strSQL As String
            strSQL = "Select Name from dbo.sysobjects "
            strSQL += "where OBJECTPROPERTY(id, N'IsView') = 1 "
            strSQL += "OR OBJECTPROPERTY(id, N'IsUSERTABLE') = 1 "
            Dim daSQL = New SqlDataAdapter(strSQL, Connect)
            daSQL.fill(dtTables)
            lstTables.DataSource = dtTables
            lstTables.DisplayMember = "Name"
    I then use the following code (In the selected index changed event from the listbox) to display the chosen table name in a label control :
    Code:
    lblTable.Text = lstTables.SelectedItem
    I keep getting the error :
    An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

    AAAAArrrrgggghhhh....whats wrong here. ASP.net is so easy.
    Last edited by venerable bede; Dec 23rd, 2004 at 09:30 AM.

    Parksie

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