Click here to Skip to main content
16,019,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai, anyone can help me. how do i connect this code with mysql localhost using wamp server and insert data in database. is this code should be written on each form to connect to the database or there is another solution to help.

(i write in login form)
VB

Imports MySql.Data.MySqlClient
Public Class Form1
Dim conn As String = "Driver={MySQL};SERVER=localhost;DATABASE=mydb;"

Public Sub retriveData()
Try
Dim connection As New MySqlConnection(conn)
Dim cmd As New MySqlCommand

connection.Open()

Dim reader As MySqlDataReader
reader = cmd.ExecuteReader()

While reader.Read()
Console.WriteLine((reader.GetString(0) & ", " & _
reader.GetString(1)))
End While

reader.Close()
connection.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
Posted
Updated 3-Nov-11 17:30pm
v2

1 solution

Open the connection once (in a helper class that you need to create).
After that, use that connection across the duration of the application.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900