Link to home
Start Free TrialLog in
Avatar of Victor Rodriguez
Victor RodriguezFlag for Dominican Republic

asked on

Connecting to MySQL Database

Hello,

Im relative new to programming world using VisualBasic.NET and I want to know how can I connect this language to a MySQL database. I want to develop an app using database integration and make a complete CRUD (Create, Read, Update, Delete, Search) functions.

Please, I hope someone helps me.
Regards,
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Download and install either the ODBC or .NET connector from this page:  https://dev.mysql.com/downloads/connector/
My reference for all connection strings
https://www.connectionstrings.com/mysql/
Avatar of Victor Rodriguez

ASKER

I have already installed MySQL .NET connector on my Windows OS. About the connection string, I selected one of the examples of connectionstrings.com page.
Have you created the appropriate user for your database?
Have you actually decided on a particular methodolgy for handling your Data Layer. You can go 'old-school' here and use the the Commands and DataReaders etc, or you can use an ORM such as Entity Framework. Personally I prefer the ORM as it tends to remove most of the actual DB stuff away from the developer. You simply create classes representing your table, and then you request instances of those objects from the EF Context. To add a item to the db, you create a new instance, add it to the DBSet and save it. Quick C# example, but I don't think it's a whole lot different in VB

// Loop through the users table
using (var db as new AppContext()) {
    foreach (var user in db.Users) {
        // user->FirstName;
        // user->LastName;
    }
}

Open in new window


// Insert a new User
var user = new User {
    FirstName = "Chris",
    LastName = "Stanyon",
}

using (var db as new AppContext()) {
    db.Users.Add(user);
    db.SaveChanges();
}

Open in new window

Yes. I created the correct user for the database.
Im looking for a Crud sample using this language and this database. Anyone can share with me a sample to see how it works?.

Regards,
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.