how to display data into a message box from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amol2222
    New Member
    • Dec 2012
    • 2

    how to display data into a message box from database

    i wanT to disply username which is in my database column3
    my code:
    Code:
    Dim cmd As New SqlCommand
    
    
            cmd = con.CreateCommand()
            
            cmd.CommandText = "select * from plane where startdate=@sdate"
            cmd.Parameters.AddWithValue("@sdate", Date.Today())
            Dim rd As SqlDataReader
            rd = cmd.ExecuteReader()
            MsgBox(" USER" &rd(3).ToString.Trim()& "PACKAGE IS END TODAY")
     rd.Close()
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    And what's the problem? Are you getting an error message? What's the message? Is it not doing what you want? What is it doing instead?

    You should also be aware that column numbering starts at 0.

    Comment

    • amol2222
      New Member
      • Dec 2012
      • 2

      #3
      on msgbox line code errror: Invalid attempt to read when no data is present.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        That error means you didn't call the read method of the datareader. You have to call that first before trying to access any of the data.

        Comment

        Working...