VB.NET MYSQL CONNECTION #0 :how to connect visual basic to mysql in visual studio 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to visual basic programming and in this particular video tutorial i'm going to show you how to connect to my sql database from visual basic code and we are going to be using a visual basic 2022 this is as a request of one of my [Music] one of my youtube followers called om yele who told me that he needs an help in there to produce for vpa.net so in response to that that is why i'm preparing this and so it is not a beginner's uh tutorial you must have some basic concepts on visual basic so the let's get started the first thing you need to start up your visual studio 2022 for me i'm using a visual studio 2022 there are those of you who might be having older versions of visual studio you i probably want to believe that you know how to go about that and in older versions it is a bit simpler so for this one you after it has started go to create new project uh we we are waiting for the template to load once they are done from the drop down [Music] list select visual basic we are going to demonstrate this on how to connect using windows form applications so select these click next here i would want you to give your project your project a name so mine i'm going to give it my sql connection and this is 2022 to signify the studio that i'm using it is 2022 once i'm done just i want to lay emphasis you can click on the ellipses here to navigate to where you usually store your visual studio project but mine i'm going to leave it under this default but make sure that you know at that particular location because it is going to be very crucial as we advance to the connection phase therefore you click next you the next page here we are prompted to select the dot net framework that we are targeting so i'm targeting currently the dot net 6.0 so just click create project let us wait for it to create the project so that we can progress so what you are seeing here it is that the intellisense window is just loading and preparing our working space so we need to be patient and this is one thing which is funny for from microsoft that it is they it is just an every studio when it loads it takes its time so you have to be patient for that so once the loading is done uh we want to change the form name here let me give it an adding of my sql database database connection so that is the title of our form and as you can see it has changed and maybe i click the ellipses to change the font i want to use uh i'm a fan of times roman so and i'm going it is going to be bold front size 14 for visibility purposes that is done then the other thing that i want to change but say i don't want to change the form name i will leave it as a default the way it is so i will go to the toolbox under the tool all windows forms just select click on the pattern and hold down on it to drag it to the form so once you have that in place you will want to change the name to btn test just press enter then we want to the next thing that we are going to change it is the label on tag on that particular text to my sql tests in a cups and then we change the font this is times roman it is bold everything there is bold just just expanded the pattern to accommodate that once we are done with that uh the next thing i want to ensure that is connected ensure that your network is is connected because we need to download uh some packages so let me connect mine i'm using that let it connect once that is done go to the tools menu after that go to the new get package manager uh get go to manage you get packages for solution just click on that a window will open and as you can see under the install the tab we are being told there are no packages found so you go to browse under browse we want to search my sql and the one with the class that we need to install it is this one called the called the called the mysql.data so sometimes there are times when you click on this class and come to you will select the solution on this particular pane it allows you it brings up a pattern for installation but for this case it is not bringing it so the alternative way i want you to navigate to this particular url which is uh this particular url and all the links i will leave them in the description below of this particular video tutorial will navigate to the top record dot net cli and use this particular pattern here to copy this file once you've copied the line navigate to where you stored your project mine it is in the documents have the issue basic folder and open that then double click that on the file explorer window on the url just type cmd and press enter on your keyboard what that does it opens a command prompt just right click on this particular command prompt to paste in that particular line of code that you've copied from this website just press enter and let's wait for the installation to be complete as you can see they're called depending on your internet connection mine has finished so i can comfortably close the command prompt and proceed to my project now if you go and click on the installed packages you will see that my sql got the data class has been installed and as you can see now the status here change from once and install uh in installed to installed so once that is done across this particular window let's progress with our testing so the second thing just double click at that particular pattern to get to the where you can place you can start coding once that is done i've pretty much written the code for testing because here we are going puddi to test whether we can we are able to make that connection so i'm going to be copying and pasting majority of the code so the first line on top of that class that you are going to will you copy this class and the discord i will leave it also in the in the description of this particular video tutorial to enable you practice so just copy that particular line and paste it on top of this particular uh class before anything else so within this class we need to make some variables so the way we declare variables in visual basic you use the word dim which stands for dimensions so we are making we are declaring this uh first variable called the con as my sql connection it holds the connection to my sql and then another variable called command which alsq which holds the sql commands so within our pattern here which handles the click event pattern of this particular pattern so we are going to write this particular piece of code so just i'm copying and pasting this because i've tested it out just a copy and paste the only line that i want to explain for now it is this particular line where we are making our connection so you see here we create a new connection to our my sql server then after making that we open we make it using a string and we supply the parameters which are going to be used to affect that particular connection so the server it is the local host meaning this particular machine which i'm using alternatively you can change that the alternative to my localhost in the ip address it is to 27 127.0.0.1 then if you are on a network environment feel free to change that to whatever ip address you've been supplied with also there are those of you who are working from there using the cloud hosted versions also change that to your respective ip addresses here i'm giving the username which i'm using for that particular database which is root then the password currently because it is the local host i don't have uh i don't have that click password set but if i wanted i can set it then the database name it is test so that is the one i want to i wanted to lay emphasis then in the try catch prog here we are opening the connection to my sql server and one if the connection it is successful we are going to display the message that connection to my sql test database was successful after that has been effected and executed successfully we close our connection then if there is an error it is caught in the try catch block and we want to know what kind of error was that so we save our work after you save your work the next thing you want to ensure of course i'm using xampp i ensure that you this mysql database server is running as you can see mine if you if you start it it is listening on point at 3 36 so 3306 so that is the point where these are reasoning on for the various connections which are coming in so you go to my local host and this is the database i've been talking about and it has got one table called users so we can now head and compile our program and see whether we are able to connect to my sql data base so once that is uh done you can see that our window has opened let's now click on this to test the connection as you can see a pop-up window comes telling us that the connection to my sql test database was successful so to also see what kind of error message we get when we turn off the server let me just fire up this control panel then switch off the server and see what kind of message are we going to get so let me switch it off and let's try to test the connection and this time round you are we are told unable to connect to any of the specified sql us that is because the server is not up and running final test let's start the server and it has started listening so click on test and you can see we get the same message that it was a successful connection so thank you i want to give my sincere thanks to om yellen for coming up with this particular question thank you so much and i feel i hope that you've learned and i've answered your question so as always don't forget to like and subscribe also share with your friends for them to continue learning hoping that in the next video tutorial i might show you how to save data to my sql database from visual basic using the visual studio 2020 tool thanks for watching and don't forget to like subscribe and share with your friends thanks
Info
Channel: programminghub
Views: 22,553
Rating: undefined out of 5
Keywords: visual studio 2022, visual basic 2022, visual basic, mysql visual basic, mysql, microsoft, MySql.Data, Imports MySql.Data.MySqlClient, MySqlConnection, MySqlCommand, Exception, dotnet add package MySql.Data --version 8.0.30, server=localhost;userid=root;password='';database=test, database, dbms, oracle, MySQL server, MySQL for Visual Studio 1.2.10, Accessing MySQL from Visual Basic, Populate MySQL Database, Visual Studio IDE, how to connect visual basic to mysql in visual studio 2022
Id: 1ZmZtO0K5e0
Channel Id: undefined
Length: 16min 49sec (1009 seconds)
Published: Wed Aug 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.