Results 1 to 7 of 7

Thread: MYSQL / VB.net

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Cool MYSQL / VB.net

    Hello All,

    I'm fairly new to MYSQL and VB.net and i'm trying to master the concept. I'd appreciate any help that could be provided.

    I have developed the following code which should connect to a MYSQL server and then take from it every value in a column called 'Username'. When running, it connects to the database and then disconnects.

    What am I doing wrong? I know that the actual connection is okay so it must be something to do with the way in which I am trying to retrieve data. Perhaps I have misunderstood a fundamental concept here?

    Code:
    'initialise appropriate variables
        Dim conn As MySqlConnection
        Dim sqlreader As MySqlDataReader
        Dim sqlcomm As New MySqlCommand("SELECT Username, Password FROM user_data", conn)
    
    Try
                'attempt connection
                conn = New MySqlConnection()
                'set connection string
                conn.ConnectionString = "server=server.com" & ";" _
            & "user id=" & "userid" & ";" _
            & "password=" & "password" & ";" _
            & "database=databasename"
                'attempt to open connection
                conn.Open()
                'notify of successful connection
                MsgBox("Successfully connected to database server.")
    
                Using sqlreader As MySqlDataReader = sqlcomm.ExecuteReader()
                    While sqlreader.Read()
                        'Iterate through usernames
                        MsgBox(sqlreader("Username"))
                    End While
                End Using
    
                'if connection is not successful then catch
            Catch
                'notify of unsuccessful connection
                MsgBox("There was an error connecting to the database server.")
                'close connection
                conn.Close()
            End Try
    Last edited by intraman; Jan 9th, 2012 at 12:53 PM.

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