I want to know if it's possible to connect to the database is use when i use PHP, in Visual Studio. I have the database hosted on a VPS server and wounder if(and how) i could connect my vb.net application to it.
And i also want to know how to get data from the database. I use Visual Studio 2010. I have VS 2012 and can use it if i need to.
I've tried to do it in the Server Explorer, and clicked "Connect to database". But i don't know if that's right and i don't know where and what to write. I know the mySql details, but not where to write them.
Yes you can, Please follow this steps :
On your class add this tow imports lines :
Imports System.Data Imports MySql.Data.MySqlClient
To connect to the MySql database, we need to use the MySqlConnection Class :
Dim con = New MySqlConnection("Data Source=localhost;user id=root;database=my_test_projects;")
Use it like this :
Try con.Open() 'Check if the connection is open If con.State = ConnectionState.Open Then con.ChangeDatabase("MYSQL") 'Use the MYSQL database for this example Console.WriteLine("Connection Open") Dim Sql As String = "SELECT * FROM USER" ' Query the USER table to get user information cmd = New MySqlCommand(Sql, con) reader = cmd.ExecuteReader() End If Catch ex As Exception Console.WriteLine(ex.Message) ' Display any errors. End Try
See This link Using MySQL Database with Visual Basic .NET 2010
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.