Results 1 to 4 of 4

Thread: Querie mysql and extract

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    Querie mysql and extract

    I'm trying to querie a mysql database and extract two fields. I'd like to store the output in a text file.

    For example:

    mysql database would be
    Field1 Field2
    a1 a2
    b1 b2

    Output Text File
    a1,a2
    b1, b2

    I'm not familiar with the VB2008 commands to do this. I've written codes using the below commands to extract a single record tied to a single idnum. How do I extract the entire database data (all the records, no idnum)?

    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`=" & TextBox2.Text
    myCommand.Connection = conn
    myCommand.CommandText = SQL
    myAdapter.SelectCommand = myCommand
    myData = myCommand.ExecuteReader()
    myData.Read()
    TextBox3.Text = myData.GetString("meta_description")

    I'm using the below code to connect to the mysql database.

    Dim conn As New MySqlConnection

    Private Function Connect(ByVal server As String, ByRef user As String, ByRef password As String, ByRef database As String)
    ' Connection string with MySQL Info
    conn.ConnectionString = "server=" + server + ";" _
    & "user id=" + user + ";" _
    & "password=" + password + ";" _
    & "database=" + database + ";"
    Try
    conn.Open()
    Return True
    Catch ex As MySqlException
    Return MsgBox(ex.Message)
    End Try
    End Function

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Querie mysql and extract

    The part in your SQL that says:
    Code:
    ... & " WHERE `idnum`=" & TextBox2.Text
    ... Remove it.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    Re: Querie mysql and extract

    How do I get the 2nd, 3rd, etc record in the database?

    TextBox3.Text = myData.GetString("meta_description")
    will only get the first record.

  4. #4
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Querie mysql and extract

    i would normally walk through the table writing out the appropiate parts to a file

    its a while not end of table

    record.movenext

    type arrangement

    here to help more if needed

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