CONNECTION TO MYSQL IN VISUAL STUDIO 2022 | C# MySQL WORKBENCH

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 cshop Visual Studio 2022 so I have created this form and which I have this button connect button if I show you its name so we have uh given its a name of connect to connect MySQL BT BTN and then we have this uh show value label and if I show its its name so we'll use underscore label so now I will show you the workbench so this is my schedule workbench so we have created this test DB inside this and in this test DB we have the students table and in the student stable we have these five records so we will connect and fetch this record and paste it or append it in that level so I'll come here I'll double click on this to create its click even so first we will create our um variables for our database and server so first I will use strength server equals as we are using a local database so we will name this Local Host and now I'll put semicolon here then we will use a string a database and our database is testdb as I have shown you here in this workbench so this DB is our database so I'll come here and now I'll put semicolon here then uh we need the uid uid equals uh which is database user ID so I'll use root and I'll put semicolon and then it takes the password so string fast forward equals and now I'll pass in here the password so the password is uh nprc e y and rate one two three you are you should use your own password Here and Now as we have created this now we will create our connection string so I'll use string uh on string equals and now here I will use a server because and here I will concatenate our server plus server and then plus then it takes the database so data base the small data base equals plus database and then Plus double quotes and here I will put semicolon I forgot semicolon here so I'll put it here right here semicolon it's comma semicolon and now here we will use our uid slope plus equals inside this double quote and then we'll concatenate if I close this so that you can see the hold code Plus uid and then plus double quote semicolon and then we will use the password so PWD equals and here I will use plus p and password and now I'll put semicolon so now this is our connection string you can see it the whole connection string and uh now we will add in the driver for MySQL so for that I'll go here to view and do solution Explorer or I can go to these tools and here I can select new get package manager no get package page packages and now I will go to this browse and here I'll uh search for my schedule dot data this one and um I'll go above and I will uh install this first one so I'll select my project and I'll go down a bit and install this now it will take some time to repair installation so now you can see a blue tick with this my schedule data dot data if I if I go to this install tab now you can see my schedule.data as well here so now I'll close this because our nuget a package myscale.data is installed so now we will access uh myscale.data so I'll make some space here and here I will use using and I'll use my SK Bell connection con equals new MySQL connection and now here I'll provide the constrain and I'll close this and close another one and then I'll use curly braces and hit enter now I'll close this solution Explorer and here we will open the connection con dot open and I'll put semicolon and then I'll create a cable command so using why are we using this using we are using this using it as a good practice because when um the end of this uh uh curly brace uh reached if we reached here so this Con uh object will be automatically destroyed and the memory will be emptied so now here we will be using using uh myscale command as it is suggesting CMD equals new MySQL uh uh Aman and here I'll pass in the query and the connection to all differently braces here now two things one is the query and the other one is the and I actually have the connection so I'll pass in the con but we do not have the uh query so now here we will create Equity so string query equals and here we will use select static from and now I'll go here and what is the name of the two table students so students and now let me call in here now I'll pass in the query here so all the user query and now put comma Now everything is working so now we will use here MySQL um data reader reader TMD now I need the object first so reader equals CMD dot execute reader and now I'll put semicolon now we have the data in this reader so uh we will get the data from this reader and we will append it to a string Builder so I'll create a string Builder here so string Builder a builder rbu equals new strength Builder and now I'll put semicolon and here we will use while loop while uh reader dot read and then we will have the first thing you dot append and here I'll use a as if I go here we have a uh five uh columns one two three four columns so this is a zero at zero Index this is at one two and three so I want these three names to that name student for father name and student address so for that I will come here use Studio and here we will use uh reader dot string and here I'll pass in one and then we will use plus double quotes and I'll make this uh if name and as space equal space and then I'll open the second index or re dot dot get string and here I'll pass in the two and then I'll use plus and I'll hit enter to create some space and I'll use double quotes space and then I'll use a address and here I'll use some space equal space and then plus um reader dot get string and here I'll pass in three and I'll put semicolon so now I'll close this down I'll make this to the middle so that I can expand the code so Al first I will add the name here so double quotes and name is equal space so now uh here we need a plus sign so that we can append this now what we are doing so uh we are getting all the data into this reader and we have created a string Builder because we have multiple records so we want to append all of them here then it uh comes and read each record and append to this string Builder and at the end of this I'll um a new line so that new record is uh uh printed on are shown on a new line so the second record similarly it will again go and fix the second record and append into this string Builder and now at the end here we will use a label values label that we have created dot text equals um EU we got two string and now I'll put semicolon now our code is complete so let's uh go and run this and check this if it is working so if I run this so now the application is running so if I click on this connect button so now you can see it has uh fetched the all the five records one two three four five and shown here so in this way we can connect to my schedule database in C sharp Visual Studio 2022 so I hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: The Perfect Coder
Views: 12,576
Rating: undefined out of 5
Keywords: visual studio 2022, mysql, c#, database, application, database connection, MySql.Data, sql, how to connect to mysql in visual studio 2022, using MySql.Data.MySqlClient;, connection to mysql in visual studio 2022, CONNECTION TO MYSQL IN VISUAL STUDIO 2022, learn c#, c# tutorial, c# programming, MySQL, Database, Connect, Visual Studio, 2022, Tutorial, ADO.NET, Configuration, Setup, Query, Code, Developer, Guide., connection to mysql database in c#, connection to mysql database in visual studio 2022
Id: pBDY20qcQps
Channel Id: undefined
Length: 11min 48sec (708 seconds)
Published: Mon Jan 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.