Results 1 to 10 of 10

Thread: HELP about simple application

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    53

    HELP about simple application

    hi! i am creating an application that is like an alarm, for example an item in my listbox is "2010-10-24" and the date in my label is also "2010-10-24".

    i would like to pop a message that there is a due paper in that date.

    my problem is my code below, it does not find the item in listbox and the label equal. i wonder what is the problem, can anyone help me? thanks alot!


    Code:
     Dim connectionstring As String
            Dim query As String
            Dim adapter As MySqlDataAdapter
            Dim table As DataTable
    
            
    
            connectionstring = "server=localhost;uid=root;pwd=passw0rd;database=purchasing"
            query = "SELECT due_date FROM request ORDER BY due_date ASC"
    
            Try
    
                adapter = New MySqlDataAdapter(query, connectionstring)
                table = New DataTable
                adapter.Fill(table)
    
                ListBox1.DataSource = table
                ListBox1.DisplayMember = "due_date"
    
    
                For Each item In ListBox1.Items
                    If item.ToString = Label1.Text Then
                        MsgBox("There is a Due Paper today")
                   
                    End If
                Next

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: HELP about simple application

    try this. i think you'll find that item.ToString is "Datarow" or "Datarowview"
    you need to cast item to that type + check the field against your label text

    vb Code:
    1. For Each item In ListBox1.Items
    2.     msgbox(item.ToString)
    3.     If item.ToString = Label1.Text Then
    4.          MsgBox("There is a Due Paper today")
    5.     End If
    6. Next

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: HELP about simple application

    vb Code:
    1. DirectCast(item, DataRowView).Item("due_date")

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    53

    Re: HELP about simple application

    hi paul! thanks for helping again.

    msgbox only displays "system.data.datarowview"

    can you explain what you said recently that "i need to cast item to that type + check the field against your label text"

    by the way my
    Code:
    label1.text  = Date.Now.ToString("yyyy-MM-dd")

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: HELP about simple application

    see post #3

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: HELP about simple application

    vb Code:
    1. For Each item In ListBox1.Items
    2.     If DirectCast(item, DataRowView).Item("due_date") = Label1.Text Then
    3.         MsgBox("There is a Due Paper today")
    4.     End If
    5. Next

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    53

    Re: HELP about simple application

    Code:
     For Each item In ListBox1.Items
    
                    Dim a As String = DirectCast(item, DataRowView).Item("due_date")
    
                    MsgBox(a)
    
                    If item.ToString = Label1.Text Then
    
                        MsgBox("There is a Due Paper today")
    
                    End If
    
                Next
    did i do it right? im sorry, i am not familiar with directcast.

    well this code only displays the items in my listbox.

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    53

    Re: HELP about simple application

    thanks bro!

    is it possible that my items in my listbox will be updated automatically without opening again the application?

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: HELP about simple application

    Quote Originally Posted by markirving View Post
    is it possible that my items in my listbox will be updated automatically without opening again the application?
    you'd have to requery the db + rebind the listbox

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    53

    Re: HELP about simple application

    hmm ok... so how am i suppose to write that? because my application is on the form_load.

    is rebind like refresh?

Tags for this Thread

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