Results 1 to 3 of 3

Thread: [2005] Problem with displaying data in labels

  1. #1

    Thread Starter
    Junior Member maco's Avatar
    Join Date
    Aug 2006
    Location
    Linköping, Sweden
    Posts
    20

    [2005] Problem with displaying data in labels

    Hi!

    When I run this code all the dataadapter is displaying is the first item in my database. None of the other is displayed. I have a database with the following values: ID, Title, Length, Actors, Description, Rating, Genre and Location.

    My code looks like this:
    Code:
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    
    
    
    
    
            Try
    
                'Open connection
                cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=movies.mdb;")
                cn.Open()
    
    
                Dim ds As New DataSet
                Dim da As OleDb.OleDbDataAdapter
    
                str = "SELECT * FROM moviedata WHERE Title = '" & ComboBox1.Text & "'"
    
                da = New OleDb.OleDbDataAdapter(str, cn)
                da.Fill(ds, "TitleResult")
    
    
                Label2.Text = "Title: " + ds.Tables("TitleResult").Rows(0).Item(1)
                Label12.Text = "Length: " + ds.Tables("TitleResult").Rows(0).Item(2) + " min"
                Label13.Text = "Actors: " + ds.Tables("TitleResult").Rows(0).Item(3)
                Label14.Text = "Description: " + ds.Tables("TitleResult").Rows(0).Item(4)
                Label15.Text = "Genre: " + ds.Tables("TitleResult").Rows(0).Item(6)
                Label16.Text = "Location: " + ds.Tables("TitleResult").Rows(0).Item(7)
    
    
                cn.Close()
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
    
    
            End Try
    
    
    
        End Sub

    Also when I try to exit the program I get this error:

    "There is no row at Index 0" - Any way to avoid that?

    Thanks!

  2. #2

    Thread Starter
    Junior Member maco's Avatar
    Join Date
    Aug 2006
    Location
    Linköping, Sweden
    Posts
    20

    Re: [2005] Problem with displaying data in labels

    Hold on! Got it working somehow!

    But 2 problems remain.

    My last question in the previous post about the error.

    And also, I can't display length in a label because it says:

    "Conversation from string "Length: " to type 'Double' is not valid. ----> System.FormatException: Input string was not in correct format"

  3. #3

    Thread Starter
    Junior Member maco's Avatar
    Join Date
    Aug 2006
    Location
    Linköping, Sweden
    Posts
    20

    Re: [2005] Problem with displaying data in labels

    Got that thing to work to, changed it from Double to Text in the database, doesn't matter which one it is.

    But that last question still?

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