Results 1 to 2 of 2

Thread: reading content in a mysql database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    reading content in a mysql database

    I looked everywhere online and I couldn't locate an equivalent VB2008 code for this php code.

    $field = mysql_fetch_assoc($result);
    $field_title=$field["title"];

    I'm trying to read the content of a field in a mysql database. I found this code below that does it but you must select the position of the field (column 0, 1, 2 etc) myData.GetString(1) instead of the name of the field. In the php code above it is "title". I'm looking for a command like myData.GetString("title")

    Any help would be appreciated.

    Sam

    ********************
    Dim myCommand As New MySqlCommand
    Dim myAdapter As New MySqlDataAdapter
    Dim myData As MySqlDataReader
    Dim SQL As String
    Dim table_name As String = "website_products"

    SQL = "SELECT * FROM " & table_name & " WHERE `idnum` = '2'"

    myCommand.Connection = conn
    myCommand.CommandText = SQL
    myAdapter.SelectCommand = myCommand

    Try
    myData = myCommand.ExecuteReader()
    myData.Read()
    MsgBox(myData.GetString(1))
    myData.Close()

    Catch ex As MySqlException
    MsgBox(ex.Message)
    End Try

  2. #2
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: reading content in a mysql database

    You should be able to replace the column by the column name between doublequotes, but it has passed a long time since i quit vb.net+mysql.
    myData.GetName(1) should give you the column name.
    check this link.
    also, if your idnum column is numeric you should not use quotes in the sql condition.
    Last edited by TDQWERTY; Dec 22nd, 2011 at 11:39 AM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

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