Crud Operation in C# | Crud Operation in Visual Studio 2022 | Perform Crud with SQL in C#

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 crud operation in uh c shop using the sql server database so i created this project in which i have nothing so we'll add some buttons into this but let me show you the connection to a database in our previous tutorial we have learned about how to connect to database and fetch data from the database so you can go and watch that now if i come here so i have created an scale connection here um i declare it here now here we have created the connection string so the first one is a data source the data source is actually the server uh this given server name so if i come here to escape server this is the data source our data source so we can use this now if i go again to this now the second thing is initial catalog which is just db which is our database name so if i connect here to this and now if i go here to database and now this is the testdb and then we have the integrated security which is true so we are using uh windows authentication to connect to sql server that is why we have made this integrated security true otherwise we if we connect in sql server authentication then you have to make this false and you have to provide the username and password for connecting to a database now here we connect to the database and then we open the database now if i go to design now i'll add in some button here so i'll use button and now i'll expand it a bit on each side and now i'll change the text on this so i'll make this create so with this we will create a table and i'll click here now i'll press ctrl and drag this to duplicate this it is not working so i'll again press ctrl and drag this so now it is working now i'll again click on this and drag this down drag this down and again i need five buttons so again now we are good to go so now i'll change the text on each of these buttons so i'll click on this and change the text to insert and i'll change this one to read and this one to update and this one to delete now i will uh rearrange these buttons so i'll take this to here this one here and i will take this below this and this one below this and now i'll place it here now our buttons are created so now i'll double click on this to create this click event so this is button one will go again to designer then button two again go to designer button three and again to designer and again to the designer and double click now we have created all the click events so now we will go to our pass button and with this button click we will create a table in our database now if i go to database and show you the tables inside this and tables so we have only three tables dbo person dbo is student and dbo users so now i'll create a new table inside this so for that i will come here to this double click on this button and here i'll create an scalable query so string this cable equals double quotes and create table and then we need to provide the table name so all you use uh my table and then i will use a plus sign here and double a i'll use double quotes and now here i will provide the column names so the first column then i will use is id of type integer and then i'll put a comma here and then i'll use a plus yeah and then i'll use a double quotes and then i'll provide the column name and it is of type of war car and a it takes 50 and then plus and then i'll use the column double quotes address and i have to provide here comma as well comma and address and this is wall car 2 5 5 and i'll close this so our queue is created now as our query is created so now i have to execute this so for that i need sql command so is cable command cmd equals new skill command and now i'll pass in this cable comma uh con here and i'll put semicolon and i will use cmd dot execute uh non query and then this non curator turns an end value so i'll use end a is equal to this and now i'll use a message box dot show and here i will pass in a dot to string because it is an integer value so we will change it to string and i will put semicolon now i will run this application so if i run this so now if i click on this create a button so it is showing an exception and this exception is near this so because we have started this but we have not ended this bracket so i'll end it here and now i'll stop it again and re-run this so now the application is running again so if i click on this create so it has shown us this value and if i go to database and now if i refresh this and if i go to databases and then test db and to tables now we should see my table inside this now we have created this my table if we go to design design now we have id and name worker 50 and address uh workout 255 that we have provided so we have created a table in our database now we will insert some data into it so i'll come to my project and stop this and i'll go to design and now we will double click on this insert and now inside this i'll copy this code from here from here up to here ctrl c this and now in this button 2 we will paste this ctrl v this and now i'll change this uh this query and i will use insert into my table and then i will provide the column names id comma name comma address and then close this and various and then i will provide in the values so 1 comma and inside single quotes name and name i will provide uh john and then we have to provide the address so inside single quotes so address will be london uk so now we have created the query so the rest is the same so we will execute we will create a sql command and then we will execute let's see if this is working so if i run this now if i click on this insert button so now it has shown in us an error and correction text near and it is not showing us where is the uh syntax uh incorrect so i'll check this so i'll stop this so again we have made the same mistake we have forgot to put a closing parenthesis parentheses here so now if i run it again and now we click on this insert invalid object name my table so why it is saying this because we have created my table if i go here and it is my table list is capital so i'll make this capital and now if i rerun this stop this and re-run this and now if i execute this insert so it is again giving us an error in the led object name so i'll copy this table name from here my table so we misspelled here the table so i'll copy this and i'll paste it here and ctrl v this stop it again and you run it again and now if i click on this insert so we have one return one so data isn't resorted successfully if we come to this and now if i [Music] right click on this and select up 1000 row so now you can see john 1 john london uk is inserted into this now the next uh is that we read data from the database so all code i will copy this first this code control see this and now i'll go to design and click on this read and control v this here and now i'll use this and i'll remove this as well up to here and now i'll use a select steric from table my table now this will execute uh so now we have to change the code here so i'll change this to sql data reader this one rdr equals cmd dot execute reader and now i'll put semicolon here and now we will get each value from this earlier using a while loop so while rdr dot read then do what then go here and use this and now we will use a string output equals and here i'll use a string out put space and then plus and rdr dot get value and i'll pass in 0 here because we have three indexes three columns id name and uh address so we will use three indexes zero one and two so then plus double quotes name space and here i will use a plus rdr dot get value get value and here we'll pass in the one and plus and then address space plus rdr dot get value and then i'll pass in uh two here and now i'll put a semicolon at the end and now i'll show this in message box so message box dot show and here i'll pass in output and now i'll put semicolon now if i run this stop this and run this so now if i click on this read so now you can see output is one name is john and addresses london uk so we have read now we will update this record so i'll stop this uh i'll copy this code so i've already copied it and now i'll go to update and i will control read here now we have to change this sql query so i'll use update i'll copy the table name because i misspelled this i'll written this fill incorrect so i'll update table name my table set name equal to and here i will pass in han so now the name will be changed to from john to if i execute this now the application is running again so if i click on this update it's one and now if i come here and refresh this and now if i click on this and select up 1000 rows now you can see that john is uh changed to han updated to khan now we have the delete query so i'll come here and or we copy this code again copy this ctrl c this and now i'll control it here and the last button and i will change this query to delete from and then the table name so what is the table name my table ctrl c and now i'll go here and ctrl v we are id equal one so now um we are good to go so i'll stop this and i'll run this again so now the application is running again and if i click on this delete so one so it means executed so i'll come here and now if i uh refresh this and now if i select top two thousand one thousand rows now you will see that we have empty here that one record was here that is deleted so this was this was crud operations in c sharp and skv server i hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: Programming Guru
Views: 3,491
Rating: undefined out of 5
Keywords: Programming guru, c# crud operations, insert update delete and read (crud) in c# sql server, c#, sql server, crud, c# with sql server, visual studio 2022, crud in c#, crud c# winform, mysql database winforms crud demo., crud in c#.net, creating crud application in winform c# hindi, winform crud, crud winform, winforms c#, crud winform c#, c# crud, crud c# sql server, c# crud sql server, Crud Operation in C#, Crud Operation in Visual Studio 2022, Perform Crud with SQL in C#
Id: htGRLW7ADeE
Channel Id: undefined
Length: 18min 11sec (1091 seconds)
Published: Thu Mar 10 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.