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 :
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: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 keep getting the error :Code:lblTable.Text = lstTables.SelectedItem
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
AAAAArrrrgggghhhh....whats wrong here. ASP.net is so easy.





Reply With Quote