Beginners C# Tutorial with MySQL Database Connection - Full Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys and welcome to beginners mysql connection c-shape tutorial and just before we start guys can you please subscribe to the channel and that helps a lot so just to let you guys know what's happening here here we have barcodes which i'm going to show you guys how to put something like that together and we have a search button here then we have the various buttons that will add more data if you want you can click on reset and let's assume we want to add new members and the name let's say the name is femi jones an address of mr jones is good man's rate mr jones mail mobile number postcode email f jones at gmail doesn't come member type let's assume it's a monthly member there all we don't need to do is just to click on add new there we go so let's go scroll right down see if we can find family jones that's mr femi jones right there one good thing about this is we can also have a look at the database and let's just click on the workbench database itself that is it mysql workbench database and i'm just going to click on refresh scroll right down and right there that's mr femi jones right there okay so we can minimize that the other thing that we can do with this system is we can actually search for any of let's assume we want to search for paul parker let's enter paul parker membership number and just click on search there we go that's paul parker's information right there and the other thing that we can do is we can also display individual data in there let's say you want to display john we know we have a lot of john in there so all we just need to do is just enter john in there and click on display and there we go those are the details of john right there all that we have is all about john and we can just delete as many johns as we want because we it seems to have quite a lot of john's from the system check this out and that is eight eight nine double four eight hit and delete gone click on the next one and so forth that's how the delete button works and now let's exit out and start a new tutorial so i'm gonna click on exit and let's click on new project now select c to c sharp and let's click on next i'm gonna give that a name i call it cs underscore beginner mysql and click on create now that my development environment is ready i'm going to make sure i click on the form and let's select properties now pin that down and what we want to do now is to increase the size of this form so let's come in here you see in the property where we have start where we have size let's change that to 1386 by 788 and just for you guys to know the choice issues the size actually depends on the um what your screen the resolution is um whatever size you decide to want to use now the next thing i want to do is i'm going to go right up here you can scroll right up and make sure you have your alphabet or alphabetical selected now coming to where we have back color let's change that very color to that blue there we go now the next thing that i'm going to do is i'm going to comp straight to the toolbox if you don't have your toolbox go straight to the windows and select reset and then click on yes your toolbox should then appear right here if you can't find your toolbox and what will happen as well is solution explorer will pop up and the properties will be displayed as well okay now that you have a toolbox you can collapse all of the dialogue to the just to the corner of your screen now select the toolbox scroll right down let's look for panel right there i have my panel in place i'm going to change the color of this very panel to control control is the default call day and now let's increase the size of the panel and i'm going to let's make that about 95 okay 1300 and by 95 that is good enough so i might as well copy these hold on to the control click and drag we need about five of i'm those to copy another one let's bring that down copy one here okay while at it i'm just going to make a brief announcement for you guys please can you kindly subscribe to the channel please that helps a lot i'm going to click on this third one just drag it that much and this very fourth one the fourth panel here i'm going to also drag that down a little bit and then let's copy one more i'm going to copy this one i'm going to be using that for my buttons just bring it down and bring it all the way down there something like that now we have every single panel in place the next thing we want to do is let's just select it all and move it right up let's tab is right up yeah that's good enough now right up here i'm going to click on the toolbox and let's add label there we go we have one label here i'm gonna copy that same label put another label here and i will need one label here i will actually need about three of those so let's select all of these labels that we have in here and increase the font size to something readable so i'm going to make the size of that very label 24 bold select bold there we go and this very one here i'm going to make that about 60 bold nice and this one we should make that 24 as well there we go bold right and this very one we might as well just change the text content of this so let's change that to my sql connection tutorial mysql connection tutorial for beginners okay that's fine just my sql connection tutorial now that is done i'm going to copy this very label let's select hold on to your control we have one and another one here in total i need nine of those okay so right underneath here first of all let's just reduce this a little bit more okay i think that will do now let's adjust as i go along i'm going to add a text some text box in there let's see text box yeah we have one here and these very text box let's change the font to 24 as well 24 there and we can just copy that we have two and we have three and here we need two here and another two here there then um let's move this up we're gonna need this one right up here then we also need a combo box let's come here we need a combo box one here another combo box let's change the font size to 24 as well something readable there and that's very combo box let's copy it right here there okay in here we need data grid view okay that is data review right there just drag it that much something like that and i need one text box here that i'll be using for this sesh and another one up here that is going to be for my barcode now we need buttons let's grab hold of buffing drag one here another button let's change the size to 24 as well and the fonts or the text content on it let's change that to search btn that will be search there and change the text contained to search there now let's copy that very button click drag and drop it here that is going to be for my exit we have to just copy and we have let's go back in yet copy again and one more thing there we go all right those are our buttons but there's one thing i should have done i'm going to copy all of these buttons let's cut them all off because i need a pattern in here let's cut i'll be back to that now let's select this that much copy and this very one that i've just copied i'm going to change the font the color to cadet blue there let's just reduce it that much so that it can fit in there we can now drop the buttons in there so come back here and just drop the buttons back in there there we go look at that all right do it okay then we get in somewhere and let's just adjust it properly and i will take care of that as we go along all right so here let's change the text content we have in here this is going to be barcode pin that down and just come in here change that to barcode right and the text box i'm going to change that to txt barcode there we go done now let's drag this that much and this one is going to be known as member id and we have first name right and this is going to be so name right okay so let's change the the names for the text box that's going to be txt member id and this is going to be txt first name and we have txt surname now let's take care of this very one here this is going to be address so the text box change that to txt address okay that is fine and this is going to be gender i will call this cbo gender then we have mobile here and the text box is going to be txt the mobile then we have this label here let's change that to postcode while we change the text content the text box here to postcode to use the postcode and here we change this one to email the text box right in front of it will be known as txt email and here that is going to be cbo member type so the label will become member type and right here i'm going to change the color of these two cadet blue so let's come back in here you can just change that to cadet blue all right and this is going to be txt search that's good now come right down here this is uh btn exit that's for the exit button come right down here and this is going to be exit this is reset and the name will be btn reset i'm showing the whole steps because this tutorial is for beginners though advanced learners can also gain a lot from this so this next button is delete the label on the button will be delete there we go and there we then have display the variable name that is going to be btn display and i say the variable name actually means this name here okay now finally we have btn add new and the outputs on the button would be add new there we go so each one of the components now have their own respective names all i just need to do now is just to tidy it up a little bit and make it look much presentable so if we run the program now this is what you guys will see so let's just save and click on run all right guys this is how the interface is looking the next thing i'm going to do now is i'm going to exit out and i want to attach the mysql library into the system so let's go straight into the project here you see the project select the project come right here you see where you have manage new gate package selected and select or click on browse inside this dialog click on browse now search for my sql there we go that is it right there you might as well select the top top one click on that and we you now have a install click on install to get it installed on your system click on ok and click on accept and there we go [Music] the system is now installed on your system all right so i'm going to exit out of this dialog let's double click on the form and we now want to import as follows okay right underneath here you see where we have the using system windows and so on just press enter we now want to say using mysql you must import our library dot data dot my sq l client end it with semicolon there we go and right underneath here you see where you have public pressure class from one you might as well just enter all of the mysql connectors so the very first one that i'm going to go for is going to be my sql that will be connection there we go and i'm going to just give it a name i'll call it sql con and that will be new mysql connection so that's the first objects that you that i'm going to add onto my system the next one is going to be mysql command that's the next object i'll just call that sql cmdb equals mysql command that's the second object the next object that i'm going to get hold of would be for the table so let's call that data table so the data table i'm just going to call that dt and that's it i'm using visual studio 2022 as you can see gives me most of the data that i need automatically appears so the next one is let's enter a variable and i'll just call that sql query so that is my query variable now let's add one more object and that's going to be my sql data adapter mysql data adapter there we go that is it right there now i'm going to just call that let's go for i'm not going to accept that and if i do i have to change it around let's say d t and that is going to be new data adapter there now i also need the reader my sql data reader and that is it right there so the instant name is going to be mysql rd there we go those are the connectors that i need for my system and the other one that i'm going to need will be the data sets there and the data set i just call that d s that would be new data set that's good so now let's create this springs the string variable that we use for the connection let's say string server and my server is going to be local localhost that's the first one and then second one that is going to be for username and the username is the root then my password my password is quite simple to remember it's going to be one two three four five there all of these will be linked to the database now for the database so i'm just going to call that database um we can just call that maybe member members that's just a membership okay membership here that's going to be the name of my database well let's put it in a quote as well right that's the name of my database okay so now that i've defined all of the components that i need for my database i'm just going to run it you guys see how the whole system looks like one more time then we can start work with the data implementation or the creating of the table itself so as you can see guys there's nothing happening right now and welcome back to the second part of this tutorial i'm going to exit out but before i go any further let's settle the database itself so let's go straight to the schema right there and just click on new this very one click on it and we want to start a new one entirely i'm going to call that membership that was the name i call it on my under codes membership now click on apply and click on apply one more time there we go my database is now successfully created so let's come into my database that's known as membership right there drop it down you see the table it's empty so right click on the table and select create table and the name of the table is also going to be membership okay now you see this arrow here the double arrow here drop it down now my very first column right here and i'm going to enter as follows let's call that m e m id okay that would stand for membership id and it's just going to be integer so i'm going to click on this that is the primary key and it's not going to be empty okay that is it right there now go to the next column i'm just gonna enter in there first name 45 is good enough you see virtual which means variable character now surname i'm going to leave that as 45 as well i'm going to enter address and after that i'll just enter let's say let's just suppose code for that include here that is fine then gender then move on email and finally i'm going to enter m type that which stands for membership type right oh we can yeah that's fine membership type m type now let's click on apply you have nine in total yeah there we go nine and i'm gonna click on apply it's successfully created that's good right so my table is now ready so if i select this table now that is the membership table if you double click on it that is it right there there's nothing i need and that's all with the table so let's minimize that all right now let's come right in here inside my table here before i do any other thing let's take care of the exit button double click on the exit button and right in there i'm going to enter try cache and the car should be right underneath here that's the whole idea is for you to handle whatever error that we might run into that was going to be exception ex there and i'm now going to enter a message message box dot show so this ex does a message that will be generated by the computer system if there's any error or by the system if there's any arrow and right in here i'm going to enter dialog result now just call that i exit there that is the name of my all right so i exit is the name of or the instant name for the dialog results so let's say i exit that would be equals message message box i would like you to show as follows dot show confirm if you want to exit so this is going to take in four arguments so that's the first argument the second argument would just be the name of my system let's just call it mysql connector that is the second argument the third argument is going to be message box button dot yes or no that's number three argument i'm going to put a comma there press enter and i will also add another argument this one is going to be for my icons so let's look for icon and the one i'm going to be using is going to be the question mark message box icon dot question enter semicolon in there now we now want to use a conditional statement to check the selection made by the end user so we will start by using an if statement if open a bracket i exit if that is equals equals dialog results as you can see visual studio 2022 has actually given me the information i need so i'm going to press coil braces if i exit equals equals dialog result.yes then i want the application to exit else the application remains within the system so if we try that out now let's run that and see how that's going to work click on exit there we go no i don't want to exit yes i do want to exit so look at the question mark that's my title this is my what is prompting the user to confirm their intention so confirm if you want to exit that from the user to compound what they intend to do so i'm just going to click on yes that is it so that's far better than just exiting out so get used to that method it's a very good ways and it's user friendly as well okay that's the first part of it taking care of let's take it off reset double click on the reset okay in the case of reset i'm also going to use the try cache as well we can just copy that and delete whatever we don't need so paste that right in here and come right down here you see all of these i'm going to get rid of them because i intend to use for each statement so let's say for each whatever we have inside control so for each control so let's say that is c in panel let's check out my partner i just want to see what panel this is select that come right here that's panel number four for each control within panel num panel four dots controls that will group up all of the controls in there and now i'm going to enter coil braces and use an if statement if c is a text box okay see if that is the object itself if it's a text box all i just want the system to do is to get it cleared so i am now going to say put that in a bracket text box close that and see let's put another bracket in there it's going to be within a bracket so the dot player is going to be outside the bracket so dot play there we go and enter parenthesis that is it taking care of that should clear the whole system but the other thing is we have some other components that are outside the panel that is one of them two and these combo box they are nuts text box so let's come back here right inside there i'm just going to enter those underneath here so let's say txt barcode dot player now t xt search that's going to be dot clay as well then cbo gender dot text and that is going to be equals nothing then i need one more cb oh member type there we go and clear that as well so that's from here up to here that should take care of my clair function okay i guess you guys can see that that's good so let's go back into our program now now before i go deep deep into the rest coding let's do one thing you see this component here i actually intend to make it backward so what i'm going to do is let me show you guys the barcode where you where you can download the barcode from i think he's here there we go that is it now the form that i'm looking for is known as c c code 39 that is a right there is a bar code c code 39 so let's search for it there we go that is a right there c code 39 okay you can download that all you need to do is click on the download link and once you've downloaded it you then get it installed that is your idea extract it okay i'm going to open it up extract it and just double click on it and get it installed i already installed it on my system so what you then need to do is select your object and then go to the properties inside the properties now come right here you see where we have font drop that down okay all i just want to do now is to change the font of these text box to see code 39 just type in c okay let's see c code 39 there we go as soon as i type in double c and that is it select that there and whatever you type in there now we then become we appear in the form of a barcode okay so let's bring that down properly and if i run the program i just want to show you guys how that works run there just type in whatever you want to type in there we go that's it in form of a barcode okay and let's make sure all our reset works click on reset there we go everything is working now that reminds me one two those are combo box i need to add some data into them so those two components this combo box let's go straight to the properties now you that you guys know how to create your barcode let's go straight into the properties drop this down and let's look for item there the first item is going to be nothing the second item i'm going to enter female and mail there that is it taken care of click on ok there we go now let's do the same thing for the next one this one select that go to the properties select items click on that and the first one is going to be that will be annual member and followed by monthly member and quarterly member there we go click on ok there we go and that's it i've taken care of those two components as well right so let's take it let's run it and see how those two components works anyway so let's see it's coming up now there we go drop this down you can select another member you can select female or male whatever you want to select that's it so that's that that's that done now that that is done let's put together some functions to get the database rolling so i'm going to now go straight into the coding area so let's scroll right up right underneath my initial initialize components i am going to create a function and this function i'm just going to copy this i'll create a function i'll just call it uh let's call it upload something like that so let's say up load data that is my function created so inside phone should upload data and now i want to get hold of my connector here okay my sql connection so the connector is going to be sql connect and that will be dot connection string and this connection string is going to be as follows that would be the server and paste the server right inside the quote and the server is going to be equals plus server that's my first connection i'm going to enter close again and open up a quote send me a column the next one is going to be the username okay so the username we can get hold of that and that's going to be username or you can call it user id whatever you want to call it that's the username so i'm going to put a plus there and the user that is going to be equals use the name plus there and the next one that is going to be let's say plus password and the password is going to be password as well anyway so we can just grab rule of the password here enter a quartz paste password right in there come out of it plus password plus there now finally we need to enter another plus next one that is going to be the database itself there we go that's the database and it's going to be database as well so put this in a quote another quote there and close it then here just type in database a plus sign there so that's the first connection that will take care of the whole system but this is the last one so we should just have semicolon there right so we now want to open up our database so say q sql connect paste dot open there we go so to get your database working you have to open it first then you have to close it at the end of the whole at the end of the whole program so now we'll get it open we also need to call sql command so sql command that will be dot connection that will be equals that so let's grab hold of all of these let's paste that in the dot connection that is equals sql there but now i want to use the sql command itself the text and what text do we want in there i'm not going to use query for now do i'm going to set doubts but what i want to use is enter my own sql statement select select all from my database name which is known as membership so it's also the database is known as membership and the table is known as membership so as a membership dot membership close that enter semicolon so i've just written out my sql statement now we want the system to read whatever we have in there so sql we want you to read as follows so what we want to do next is let's ask it to just so let's say sql read there we go that's the read that is going to be the command dot execute there i've just been given a hint of what to enter in there that is good now that we've done that we also need to get it loaded so to load it we need the data table so the data table let me just name it as data table so that's going to be sql let's change that to sql dt so that i can see it properly yeah that's it the choice is just how you want to name yours so my sql dt will then load up the system for me sql data dot load and that is going to be load the reader that is it right there now that the radar is loaded we also want this reader closed sql reader dot closed that is it right here reader there we go we'll just close that as well okay now the next thing we then need to do is since we've closed that we also need to close the connection so this is a connection there sql connection that must be closed dot closed once that is closed let's get our whatever is loaded into my data review so i'm going to say data grid view there's a great view one dot the data source and that is going to be sql dt this very one year entertainment column and that is it i've just finished loading up my database okay one more thing let's put together another just one more function this very function is just to generate random number for my bar code so i'm going to get rid of all of this and that is going to be reference number okay that's that's okay okay that is the name so let's use random function yep random and what's that going to be okay we just say run that would be equals new there any random itself is going to be let's say let's create an integer then we call number and that very number is going to take in random.net and we just need to enter some value in there so let's make up some value for that that is going to be let's say 5 000 plus right let's reduce this okay that's the range of the random number so we can make this about 32 plus okay that's fine there that's my random number range so we can then say um txt barcode dot text that is equals we also need to okay that's random to string okay number to string if i call this now inside the form load let's call this inside form load and you will see that right away so come right down here double click on the form paste there if i run it it would automatically generate random numbers for me so let's see i've just clicked on run so we're waiting for it to respond look the random numbers generated but i want to kind of like fill it up so let's go back in there i also need a mirror so i just call the yeah this one load let's come right down here call that from load let's follow the devgo i also wanted to to load up the database there now come back here to my function this very function where is it there we go this is the function in here i'm going to enter some text in there yeah why not so i am now going to say just to fill up youth add a additional additional reference okay additional reference let's say plus i'm going to convert whatever is in there.string dot to string and what i'm converting that to string is going to be number and just multiply that number by 12 just fill up your place so that should fill it up so let's run it one more time and see that run onesie number generated oh let's see what was the arrow all right equals sign is missing right here there was meant to be an equals here so guys please remember to put your equals i left this out mistakenly there there should be an equals all right i think that is fine okay let's run it one more time run the missing equals was from my load data that was the function you see that is what i'm talking about and as you can see automatically the database is now recognized straight into or straight onto my data review okay just with this very function that i've created okay so what we need to then do is to when we click on this add button whatever data we enter in here should be stored right into the database itself this is very database and also start on my data grid view but take a good look at my data grid view there's one or two changes we need to carry out on this data review itself look at the data that's the table all of these data here is right from my sq my sql database here okay you can see it's not filling up my data grid view so i'm going to exit that let's select the data grid view go to the properties inside the properties we now need to carry out one or two changes i am going to first of all have a look at the auto size color mode auto size let's see there we go other size color mode i'm going to change that to all cells then the next one is going to be auto size roll mode i'm going to change that to all cells as well make sure you guys do that come in here to the properties again the next one we need to take care of is going to be the default cell style default sales type we need to increase that where is it right there that is it select that i'm going to make that about let's come in here make that about 16 make that bold that's one what about the pattern maybe change the part into two by two by two let's say two by two by two and by two if you want to change the color or whatever it's right there you can just take care of that as well click on ok let's take care of the column that will be the column column header column header height and size that's auto okay column header height and size default select that and we need to change this one to 16 as well there we go and i'm just gonna make this two by two by two there click on okay okay now let's just run it one more time the changes should now take effect so let's see there we go look at that okay it's now bold so when i enter my data that will stretch out everything okay that's fine so let's exit out and start work with add new data so double click on the button add new data now before i can do anything i'm going to copy the sql statement inside this very function where is it right there i'm going to grab hold of that sql connection string grab hold of that and let's go back into my button double click on that button again paste that right in there but before that i'm going to use try try then in there i'm also going to use polish statement exception right in here enter a message for my errors whatever i might run into dot show i'm just going to use the system one ex dot message okay let's enter the ex in here so this would be ex dot message that should hopefully take care of whatever error i might run into now so right in here the next thing that i'm going to do now is let's come right underneath here and let's open up our database so sql dot open and once it's open i also want my query the query is right up here i declared it right up here somewhere there we go sql query i'll be using that in here sql query that would be equals we want the system to insert into membership that is the name of my database if you guys can still recall membership dot membership as the database name dot the table name is also known as membership and i will open up a bracket and this very bracket is taken in the following member id comma first name comma all of those are from my database so name comma i think yeah i do have address comma i have postcode let me check that postcode comma i didn't have gender and let's see if we can just feel yeah we should be able to do that and go to the next line gender then we have mobile comma email admirers will just take you to the next line press enter okay we have email and finally we have m type right those are my columns now the next thing is going to be the value so let's say the value i'm going to enter plus in there and the value that is going to be as follows let's say value values single quote double quotes plus the first value is going to be txt member id dot text that's my very first value plus double quotes single quote comma single quote double quote then the next one this is going to be plus txt first name dot text right so now i have my system now sorted so i can just copy and paste that the next one here that is going to be txt surname dot text paste and we have address txt address the text paste assorted then we need the postcode txt postcode text test very good then we have gender cbo gender the text paste our gender is in we now need let's come down here enter the mobile txt that's mobile the text there now txt email text paste um finally cbo member type dot text and that is plus call single open a bracket i'll close the bracket and there we go so those are my components that go straight into the tables total that should be nine now we need a command we need a command to okay let's first of all say sql command that will be equals new objects you know sql command and this new sql command then test takes in the the query and also the connector now that that is done we also want the system to read it sql read dot execute or equals command equals sql command dot execute reader there once all of that is done you must then close the sql connector dot close and enter parentheses and that is it done okay now that that is down you see underneath here you can just say let's say finally i want you to just close everything for me make sure it is closed and once it's closed i want the following to happen i'm going to copy this paste that underneath there and right underneath here i'm now going to call my unload function now it's called upload upload data the function and yeah i might as well call the reference number function as well reference number ref number here i guess that is what it's called no that's a t that should have been f right and that's i believe that's all there is to to eat for add new data so have a good look at the lines of code take it from here okay that is for my server and so on now open the database now put together your sql statement okay enter all of the columns and the data that goes into the column the location of the data the idea okay those are the text box and the combo box that i use now let me just save and run to confirm that it's working run there we go there's no error okay let's enter data in here that is my password and the name is johnny davis an address of johnny davis that's going to be 109 goes down and here mail mobile number yeah and the code email john journey arts gmail and member type i know there that is it so decision time i will now click on this there we go look at that i've been able to add my data let's see if he's going to accept the same primary key nope duplicate okay thank you it's working and to then check if this information of john is added to my database i'm going to click on the database here look at it there's nothing in there so i'm going to have to click on refresh there we go look at that the information of johnny is added to the database as well that is brilliant so let's exit out there we go now the next thing that we want to do let's double click on you see days let's double click on this and do as follows no we don't double click on it let's come straight to the properties and select event inside the event and i want cell click right there so double click on the cell click so right inside the cell click i going to start by entering try cash take care of my errors so let's enter a car statement here copy that paste that right underneath here there and first of all i'm going to add as follows so whatever we have in there once we click on it i want the data to be displayed on the text box that's the whole idea so the very first text box is txt member id txt member id dot text and that will be equals data review one dot select let's do select rows and that is going to be zero dot cells and the first one is on array 0 dot value and dot to string there we go so that is the very first one so i might as well just copy this i'll change the rest around anyway or just copy these the next one is going to be txt first name so let's copy up to here and paste so this one is going to be one txt store name paste and that is going to be two that's good yeah that is good and we have txt address dot tax that is three visual studio two 2022 actually recognized what's happening which is good so we now want the next one that would be cbo gender there we go that's fine now txt mobile and dots text yeah that is correct yeah then we have mobile we also need txt good the text that should be yeah that is correct as well then txt email and finally cbo cbo member dot text there and that's it save that if i run it now i should be able to click on the data grid view and whatever data i have on the data review should be distributed onto my data here so if i click in here check that out you see that that's the whole idea that's very good now let's come down here we now want to take care of display double click on display using tri cache all i just want the display to do as well is just to more or less search so i'm going to copy that paste that in here so this one is going to be session d data agree with you for me so i'm going to say data there the view i'm going to call the dv that's where we equals sql data dot default default view and dv dot row filter that to be equal string dot format and what are you formatting let me use the first name so if you enter first name we should be able to find every other details first name like let's put that in percentage and we have curly braces zero curly braces and close the percentage with the percentage and close the single quotes now come out comma txt the text there we go all right so that is done so in that case where shall we display the data we want we shall get the data that we want displayed inside the data review dot data source which is equals to dv dot to table there we go and that's it so with these if i have more than one record you should be able to display the ones that i want so let's save that run it and see how that's gonna work let's see it's coming up so i'm just going to select this setup and speed up things now the name here is tony tony johnson and that's and change the address that's all road postcode that should be the postcode i should have been mail and this is the postgrain maintenance rom my arraignment seems to be wrong okay now this one that should have been postcode and the other is right so that's tony jay tony tony happens to be monthly member now click on that there we go okay now let's assume we want to look for one of the members let's say we're looking for johnny and click on display only johnny will be shown okay that is how it works i think the other one is tony now click on display and tony tony's details is displayed as well okay so that is fine working as we want okay there is something here i'd like you guys to have a look look at that so gender has changed my code in here needs to be readjusted so let's exit out okay come right in here the following needs to be changed postcode i'm going to make that four and mobile i'm gonna make that six then gender i'm going to make that five so their rearrangement should be doing men should be something like this okay i think that should get it sorted now okay so let's save that and run it again so each individual data should be in their right cells so if i click on here mail okay that's fine it's working as i want that's very good so we now need to take care of delete and the search button okay let's exit out and i'm going to click on the delete button here to start work on the delete but first and first i need some data in here so let me just copy i'm going to copy everything that i have in here up to here just copy that i'm actually copying the codes inside the add function so let's go back to my delete button again just double click on it and paste that in here now i'm going to get rid of these i don't need that we have to write a different sql statement for delete and i'm going to get rid of the execute okay now what we then need to do is to use command let's say sql command dot command text and inside the command test i'm going to enter my delete function my delete sql statement delete from membership dot member membership dot membership does the name of my database and the table is also known as membership and that's gonna be where member id is equals as member id okay so the next thing that we want to do now is to now use command.new okay the object to refer to the query that we intend to delete and where the connection is that is fine then we close the database okay that is fine then the next thing that i want to do before i leave is first of all let's enter semicolon there i now want to whatever we delete i want it deleted from the data review as well so i'm going to use for each let's say data data grid grid view rules i need rules let's say rows might as well type it out bro yeah this very one for each data grid view row item and this data that would be this dot data that should be this data this is the data grid view is the data grid view one dot select rows selected rows okay then in there i'll then say date agree view one dot row is that there is agree if you want dot rules that should be rules uppercase dot i'd like you to remove at item index remove at item i want item index item dot index index there we go and that is it that is all there is to that okay so i'm gonna save that and let's just try it out and see okay let's run it and see what's gonna happen hopefully that should work run so there we go we're running the system now i am going to just more or less like clone this let's change the the variable or the yeah let's change the member id then i'm gonna change it name to maybe tony tony allen and i will now add tony allen details straight let's say a20 here and change this as well let's click on add so click on add there we go so now let's get rid of one of these select that and let's come in here and just click on delete there we go look at that we've got rate read of that but one other thing is i've got rid of that but i still have it on mine i still have it right here okay so to do that i might as well call this very reset okay let's add it again i'm going to add that let's see oh duplicate it's not duplicate let's change that add we have it back in the system so i'm gonna call this very button to delete whatever i have in here so let's exit out exits yes let's go back in here so right here i'm just gonna call btn reset underscore click so let's just call it all at one time btn underscore click then get hold of sender send that dot e there we go right that's all i need so make sure it's saved run so i'm going to now be i should be able to delete them both okay now select johnson okay now i have two of those because i click on it twice now delete and whatever i delete i should be able to delete everything in here as well so click on delete there we go look at that that is fine so we now need to take care of the search function this one here should be able to search just by you typing a name in there let's assume we say if we have the loop for johnny if you click on this that should just display johnny page just to filter it and this one you have to just search by we use this one to search by numbers so i'm going to exit out let's click on the search button go right up there double click on the search okay for the search function let's go back to my [Music] add button here i'm just going to copy some other lines of codes in there so maybe just get hold of all anyway let's grab it up to here copy that again now let's double click on that very button double click on the search button paste that in there now what i don't need i don't need this i don't need the connector it doesn't need to be connected to anything so get rid of that now here the query i do need a query but i don't need all of these so you just get rid of all of this here in there all we just need is let's just select from let's just select all i should be starting this select all from membership dot membership the membership remember like i said that is the name of the database and the table is also known as membership that makes life easy for me so select from membership where name id is equals as follows let's enter an equals there single quote and double quote and it's going to be session inside txt search dot text it's a plus double quote single quotes w and there that is my search sql statement or lines of codes there you now use the command to carry out your execution here that would be the system we have to read okay then close the database but before i close the database i want to use an if statement here let's come down here to validate whatever we have i'm going to copy the sql reader and i'm going to say if sql read dot read in that case i want the following to happen so enter curly braces i want you to filter through every single text so let's every single component i'm going to copy those components here instead of typing it all all over just copy that and come right down here where am i yeah that's my search paste that right in there and now i'm going to then delete everything in here so let's just say reader sqlread dot get string so come in here paste that in there dot get string and the string that we're getting in the first instance that will be member id there see how easy that is now so i might as well just copy this and change it around for the others let's paste that in here now you guys understand why i copied it so i will just change the data to whatever i have on each column of my database right there and there we go and here that's going to be first name all is in lowercase then we have soul name here changes to song name i have address here then i have postcode here i have gender mobile any email here and finally i have member type m type i call that there we go else i just want a message box to say data not found so we can just enter that in there message box dot show let's say no search data or no data found something like that no data found we can just enter title to fight mysql connect to then comma enter another argument cover message box button dot okay another argument message box okay that would be error then oh no okay we can use error or information whatever you want to use that's fine all right if you want to change this all you need to do is select it and double just entire dart and you select whatever you want i'm going to select information okay that's informing the user that the data is not found now we also need to make sure we close the database and that is all to the search function okay have a good look at the lines of code for this search take it from here bring it down and that would be all let's just get this one let's press enter here to have it on two lines all right so have a good look again take it from the top search bring it down there and i'm going to save and run and let's see how that works right so let's look for anybody in here so i'm going to select these and just enter that's a 4 5 5 3 five four search there we go look at that that's johnny davies so with that guys i'm gonna call it the end of this very very beautiful tutorial for beginners i suppose you guys enjoyed and please do subscribe to the channel i am trying to get to 1 million subscribers and hopefully i should be able to do that with your support you all have a nice day now and thanks for watching bye for now
Info
Channel: DJ Oamen
Views: 6,025
Rating: undefined out of 5
Keywords: How to Create a Data Entry Form in C#, Overview of a Beginner Data Entry Form Developed in C#, C# MySQL Data Entry Form, C# Beginners MySQL Database, How to Create a Beginners MySQL Database in C#, Beginners MySQL Database in C#
Id: qjrbEZk9_ZQ
Channel Id: undefined
Length: 92min 57sec (5577 seconds)
Published: Sat Jun 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.