MySQL Database WinForms Crud demo VS 2022 | C# Create Read Update Delete with MySQL

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 crowd operations in C sharp and MySQL one of the subscribers asked for this video so we are making this video so I have created this these buttons as well as this text fields and this data grid view so let's start first I will double click on this button to create this quick event and now here we will create our connection to the database so first we need the drivers part or the uh MySQL connector for a connection to mysqable database so for that I will go to this tools and here I will search for nuget package manager and I will so click on this now I'll go to this browse and here I'll search for MySQL dot data and now I'll click enter so now it has loaded this mysql.data you can also alternatively use this uh here we have another one so now it is not accessible right now here but we have another myscale dot connector you can also use that as well so now I'll click on this and now I select this and now I'll install so now it is successfully installed if we go to this installed now you can see this mysql.data here so I'll close this nuget package manager and now here I will create a the variables so first we will get the server name so server equals so you are using a local database localhost now we will create the database first so for that I will come here to this and here we will search for xampp control panel so I'll open it now I'll start this Apache as well as my schedule now I'll go to this browser and here uh I'll search bar localhost and it will go to dashboard and now we will go to this PHP mind men so it will open up this uh PHP Mad Men which is MySQL so now we will create a new database here in this mySQL database so here I'll click on new so we will give a database name here so crude operations and now let's click create to create the database now you can see these crud operations database is created here now we do not have any table in it so I'll go again here to visual studio and we will start creating uh our connection string so here I'll use a user uid which is database user so we are using the root user in the database all but semicolon here then we will use a string password and this is uh empty because we are not using any password and then we will add the database name so string data base uh equals um crud operations and now which is this one if I come here uh to this browser so this is the database name code operations so now I'll come again to visual studio and now we will go to our um our design and I'll double click on this create table as we have already created this uh button click event so in this we will create the table so first I will create the connection strings for string a con string so it takes the server name first so we will use a server equals and here I will use plus and here I will use server then plus and foreign and then space um we do not need space here so then we have the user ID so uid equals and here I'll pass in the uid so uid plus and then double quotes then semicolon then it takes the password so PWD equals and then here we will pass in the password so password and then plus and then double quotes semicolon and then we need the database name so data base equals Plus data base and now I'll put semicolon at the end so this is our connection string now and we will use myscale connection so my SQL connection this one uh con equals new my S cable connection and here I'll pass in the connection string as is already telling us to put the constant string here now I'll put semicolon now we will so here I will use string p8 table equals so user create able and we will give it a table name so test underscore able and then we will put small brackets and inside and this these small packets we will create The Columns of this table so first will be ID of type end then I will put semicolon then I will uh create name it is a work or 50 and then we will close the small bracket and then we will use a the class and here our father name f name and it will be also work or 50 and now I'll close this and now I'll put semicolon here at the end now we have created our query so now we will use MySQL command so my is cable command TMD equals new my schedule command and here it is two things one is the query and then is the connection so we will use create as is already showing us that here it goes uh create papers in here uh fun and now I'll put semicolon at the end now as we have created this now we will use uh int I equal to TMD dot execute none query and now I'll put semicolon here now I'll use a message box dot show and here we will use a now we will put semicolon here and we will run our application now if I run this so now the application is running so if I click on this create table now we have an exception here's uh connection must be valid so we haven't opened the connection so I'll come here and uh on Dot open and now I'll put semicolon now we will stop this and run in again now it is again running so if I click on this create table now we have 0 and now if I go here to this and now if we refresh this now you can see a test table is created here with um you can see this this table is created with ID name and F name now we will insert data into it so for that I will close this come here to this and stop this and now we will go again to design and now we will click on this insert button so now I'll copy this code from the top from here up to here and now I'll Ctrl C this and now we will control V8 here now we have a uh we only need to change the query so I'll come here and remove all of this and now we'll create the query transaction the user insert N2 and then table name so test underscore table and now it takes the column name so ID name and F name and then it takes the value so values and then small brackets now here we will provide the values so I am going to get the values from these text boxes from this one this one and this one so for that I will come to this and here I will use single core double quotes and then inside this we will use a science plus and then text box Dot next now we will put a comma at the end of this and now as this first text box gave us the ID so this is integer value so we haven't put a single quotes around it but if we insert string values work or values then we need single quotes around it so first I will insert a single quote single quote and then inside this I will insert double quotes double quotes and then inside this I will use uh two plus signs and then X box 2 dot text and similarly I'll commit end here inside this single quote and then we will put further name is also I work our value so I'll use single code single code then simple code double quote and then um thus us and then Xbox three dot X text and now at the end of this we will put semicolon which is already there now the rest of the code is perfect so one may ask where these columns names come from so if we go to the browser into our database and and database table so this column names comes from this data a base columns ID name and F name if I go here and I show you ID name and F name and these are the values coming from text box so and now I'll close this or close this as well close this as well so we have this space available and now I will run the application so now the application is running so if I enter here 1 and here if I I enter MIT and here if I enter Han and now if I insert a data in table so now one is shown here it means that I successfully inserted so now if we go to our browser and now if I refresh this so now you can see one Mikey and Khan is inserted now if we insert another value if I make this 2 and this then veer foreign table now I will insert another day record as well so I'll make this free and this uh Ali and this girl and now it finds out now this is inserted okay now if I go to this and now if I refresh this now you can see three records are inserted here now I'll go here to or I'm a application I will stop this now I'll go to design and now we're gonna read this data that we inserted in the table and we will put it in this data grid view so for that I will double click on this now we already have the code so I'll copy this Ctrl C this now I'll Ctrl V it here and now we will change this query and backspace this and audio select static from test underscore table now the query is created now I'll uh from here and I will remove these two lines of code because we need something else here so I'll use MySQL data reader reader equals CMD dot execute reader and now I'll put semicolon I will create a data table here DT equals new and now I'll put semicolon here and now we will load this reader into this DT so get the table Dot dot load and we will small package here so shaped small packets and we will call load the reader into this data table and I'll put semicolon now we will go to design we're gonna uh give this data table as data source to this data grid view so what is the name of this data grid view its name is data grid view one so if I close this now if I go to this now I will increase the size of this code so that it is clearly visible now I'll use a data grid V1 this one dot data source equals DT semicolon now if I run this now I'll um click on this read from table so if I click this now you can see all the threes record three records are read read from the database table and um shown here now we will update a record in this and we will delete it record in this so I'll close it down so we will change this ID to a tanveer 2 um Ahmed so I'll close it down stop this and now I'll go to design I'll double click on this update and now I'll copy the code again I already copied it so if I control V it here it is here so I'll remove this query come to here now I'll go here to this side and now here I will use a update and then table name so test underscore table and now we will use set name equals angle codes angle code and I'll use Emma via ID equals to so and we are changing the id2 name so now the rest stop is is uh perfect so we will run the application so now I learned first uh read the table now we will update this we are going to we are going to update this id2 so if I click on this update it is saying one so now if I read it again so this then we should change to ml and now you can see then we change to m now we will delete this uh third record so for that I'll close this and now I'll go to design again I will double click on this delete button and I'll Ctrl V it here we just need to end this query so I'll come here and remove this and here we will write the query as delete from test underscore table we are ID equals e and now our query is complete so now I'll run it again now the application is running again so I'll read from tables we have these three chords now if I delete this it is saying one which means it is successfully executed so now if I read it again we should have two records and it has two records so this was our Cloud operations in C sharp and my schedule I hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: Programming Guru
Views: 8,803
Rating: undefined out of 5
Keywords: c# tutorial for beginners, c# tutorial, c# programming, c# full course, MySQL database WinForms CRUD Demo., MySQL Database WinForms Crud demo VS 2022, C# Create Read Update Delete with MySQL, CRUD C# MySQL, C# MySql CRUD, Insert Update Delete View and Search, c# mysql - insert update delete view and search, C# CRUD Operations Using MySql Server, Add Edit Delete View and Search in C# MySql Application, MySql CRUD, crud c# mysql, c# mysql, c# crud, vs 2022, visual studio 2022
Id: x_xASm0WEXA
Channel Id: undefined
Length: 21min 23sec (1283 seconds)
Published: Mon Nov 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.