C# SQL SERVER | How to Connect Sql Server with C# 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 uh connecting to escape server database in cshop so let's start so first we will uh go to this app.config file and here we will create the connection string so for that I will use here the connection strings property and uh I'll close this deck and now inside this it will take the Ed again here it takes the name so it will be the name of our connection string so I'll use my con string and then it takes the connection string itself so the connection string consists of multiple things first is the data source so data source is actually the server name or the database in the name so for that I will come here to this Escape sermon in studio I'll disconnect this and then I will click on this connect and now this is the server name so I'll copy this and uh now go here and I'll paste it here now this is the server name so I'll put semicolon uh here now then it takes the database name which is initial tag equals and here it is the database name so if I show you the databases so if I connect here and go to this databases so we will connect to this student's DB so I'll go here again and I'll use initial catalog as a student DB semicolon and then it takes the integrated so if you you are using a window authentication then you use your Loop and now if I using uh this given server identification then you use here files and provide the username and the password so we will use here true because we are using the windows authentication now so we have this uh SD table inside this uh student DB if I show you this St table here so this is here and we have these two records in this SD table so we will read these records from it and show it so I'll come here and now as our connection string is created you can see it here now we will go to our uh form uh design and I will double click on this button to create its click event so now here we will first uh get our connection string so I'll use string con string equals and here we will use configuration manager manager to access our app.config file configuration file so I will hit enter so it will automatically uh get the library or the reference if you can't find here so you have to right click on this and add references and then you can find it here in the system ah so here it is system dot configuration so you can add it and then after this I will put a dot and then we will use connection strings and then we will use uh square brackets and that I will use double quotes and then we will get the name of our connection string from here so its name is my constraint so I'll copy this and now I'll go again go to this form dot design or double click here and I'll go here and I'll control V here now I'll use here dot connection string for connection string we have access our connection string here so now I'll hit enter and now here I'll close this window and now here we will create our SQL connection so I'll use using SQL connection on equals connection and then it takes the connection string on string and then we will use curly braces now inside this we will open the connections through con dot open and now close this now we will use the if cable command but before that we will create a queue resource string select think pretty equals select double quote so select static from HD table which is this table SD table so I'll come again here now I'll put semicolon here now this is created so now we will use using and here we will use this cable command why are we using this using uh because when this object is created so when it reached to the end of this uh curly brace so it not this one but this one this curly brace so it knows that this cable connection object is uh no more uh required so it automatically uh destroyed so that is why we are using using this is uh the best practice so I'll use same D equals new and cable command so the C is capable here so I'll use and now I'll close back it and now I'll put only places at the end and now here I will use a query and then I will use comma and then I will use connection click on so now our Command is created and we have provided the query so now we have to execute this so I'll use its cable data reader reader equals new it's given data not new visceral data reader but CMD dot execute leader and I will close this semicolon now this is created so now we have all the data in this reader but we will read one by one so while we will use while loop uh reader dot read so I'll use this and now I'll use curly braces so here I will create a string Builder so string Builder equals new string Builder and now I'll close this semicolon now so we will get all the data from it so we build a edit the string as Dot that bend and uh we will use the reader Dot string and here we will use uh zero and 0 is uh ID so I'll use one and then I'll use plus and double quotes and then plus uh a reader dot get string here we will pass into and then Plus and then double quotes and then space space and let me check that how many columns we have so we have 4 so this is 0 1 2 and 3. so now we will use three so Plus and the reader dot get string and here I'll provide so now we are good to go now I'll show this Builder and a message board to message Dot show and here I'll pass in Builder Dot and now I'll put a semicolon at the end control acid and now let's run this and let's check this now if I run this application so now the application is running so if I click on this uh fetch data now you can see Ali Khan and Peshawar now if we go to the table so the first card is Ali Khan and peshava and now if I click ok then the second record will be fixed but it has filled the second record as well and append it because we have appended it in the string Builder Han Ali Islamabad to and if I go here and search Han Ali Islamabad 2. so in this way you can connect to the database and fetch record from disabled server database in Visual Studio 2022 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: The Perfect Coder
Views: 6,594
Rating: undefined out of 5
Keywords: connect to sql server 2022 in visual studio 2022, CONNECTION TO MSSQL SERVER IN VISUAL STUDIO 2022, c# sql server, c# sql, sql server c#, connect sql server with c#, sql c#, how to connect sql server with visual studio, c# connect to sql server database, c# mssql, sql connection in c#, c# mysql, c# sql connection, c#, c# and sql, c# database, mssql, connect database c# sql server, c# connect to sql server, c# ms sql, c# with sql, how to connect sql server
Id: kezCP0RZfGk
Channel Id: undefined
Length: 10min 33sec (633 seconds)
Published: Wed Dec 28 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.