How to Connect to MySQL database in c# | C# MySQL connection in Visual Studio 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my channel today in this video tutorial we are going to learn about connecting to my schedule database in c sharp so i have started this zone uh control panel this apache server and this mic schedule database so i'll connect to this so i'll search here localhost and it will take me to zone as exam control panel now i'll click on this phpmyadmin and it will take me to this database and i have created this test db here and now we have this student table as well as this employee table so if i click on this employee table now it has these records so we will connect to this database and we will read these records from this employee table so now i'll go to um visual studio and here i will create a new project now it will be a consoleable.net framework and i will click next and now here i will use connect uh my sk well and now i'll click create to create the project so now the project is created so we will quickly add the library or the preference for mysql so i'll go to this manage nuget packages and now here we will so we will click on this browse tab and search for my sql and now we will add in this first reference install this and click ok and accept now the package is installed so if i click on this represents you can see here my schedule dot data so we have added successfully my schedule reference into our project so now i'll come here and we will create some code to connect to mysql database so first we will create the connection string so for that we will mention the server so string server equals local host semicolon then we have a database string data base equals um testdb which is uh this database testdb and we are on localhost now i'll put semicolon here then we need uh username so string user name equals root so we are on the root user of the database and then string password equals empty empty semicolon now we will create the connection string so string con string equals our first one is uh server so server equals plus on server this one plus double quote and we will use semicolon inside this double quote and then plus then we will use database so data base equals [Music] plus test db or database plus then we will use semicolon and then not comma but semicolon and then plus then we will use a user id so for that i will use you id equals plus and here we will pass in user name plus and double quotes semicolon inside double quotes and then plus we have a password so double quotes password equals plus uh password plus double quote and semicolon and now we will add in a semicolon at the end so now we will create mysql connection so my sk will connection this is capital connection equals my um is cable connection and here we will pass in the con string so now it is showing an error so we will import this so if i click here on this arrow so we will import this mysql dot client so this my schedule connection is showing error because we forgot new keyword here so new my schedule connection now the error is gone so now we will create uh open the connection to con dot open and now we will create a query so string qre equals double quote select static from employee which is our table and now i'll put semicolon here now we will create this cable command so it's my schedule command command and cmd equals my sql command and here i will pass in the query and the connection and now i'll put semicolon here here i forgot the new keyword again so i'll use new space and now i'll put semicolon here and it will go down and create some space now we will read uh data from this command so we will use my sk well data reader reader equals new cmd dot execute reader and now put semicolon here and now so this execute reader is showing an error because it is end execute reader so i'll remove this end from it and now we will use while loop while reader dot read then do what then console dot write line and here i will pass in reader and my column name so the column name is the first one is a e number and now i'll copy this and it will see this and now i'll paste this ctrl v and ctrl v again as we have three columns in this employee table employee number employee name and employee designation so i'll come again here and if employee name and this one will become employee dizig nation now let's run the application and check it if it is working so if i click this run now you can see that all the records are paged and shown on the console so we have successfully connected to mysql database in c sharp and fetch the records from this employee table so i think that's all for today i hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: Programming Guru
Views: 43,529
Rating: undefined out of 5
Keywords: create an interactive mysql database connections, ow to connect mysql database in c#, Connect C# to Mysql, connection with mysql in c#, how to connect to mysql using c#, how to connect to mysql server using c#, connect to mysql database in c#, how to connect to mysql database in c#, Connect mysql to C#, connect mysql database in c#, how to connect to mysql database, C# MySQL, MySQL C#, C# MySQL Connection, connect to MySQL in visual studio
Id: n1QarlZj3lM
Channel Id: undefined
Length: 10min 10sec (610 seconds)
Published: Mon Dec 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.