How to Connect to MSSQL SERVER in C# | How to connect to sql server database in c# | C# SQL SERVER

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 microsoft sql server in c-sharp window forms so i have created this window form and i have nothing on it now i will go to this toolbox and i'll drag in a button on this window form and now i'll expand this button a bit and now i'll change the text of this button to connect to this cable server and now as the text changes now i'll double click on this to create this click event so now our click event is created so now here we will write some code which will connect our form to the database in sql server so i have opened this is given server management studio so if i go to this click on this so this is our server name so we need this uh so i'll copy this ctrl c this now if you have installed microsoft sql server and microsoft sql server management studio and you double click on management studio and open it so you it will show you your server name here so you can copy this ctrl c this and now i'll again go to visual studio and now i'll you create string con string equals and now i'll put a double quotes and i'll put semicolon here now here i will use data source equals a non paste or server name and now i'll put semicolon here then we will use initial catalog which is our database so if i go to the server and connect to this server and now if i expand this databases tab now you can see this testdb here and inside the steps testdb we have tables if i expand them so we have this person table in this student table so if i select rows from this person table so we will be reading all this record from this person table id name and address so i'll come again to visual studio and i'll use here initial catalog equals testdb db and then i'll put semicolon and then we have our integrated security so i'll use integ created security equals true so if you have a username and password uh you have applied here if i close it down and if i database engine and if you have a username and a password here is given server authentication open as we have in window authentication if i make this escape server authentication then it takes a login name and a password here so if you have a login name and a password so then you use integrated security false and use that password and a login name now our connection string is created so now we will create our connection so this cable connection con equals nu s cable connection and i'll put seven coil in here now this is showing error so if i click here now i'll start using this uh system dot data that is cable client and now i'll click enter and now i'll pass in our connection string here con string so i'll open this connection com dot open i'll put semicolon here so now i'll create our qris string qd equals um select static from person which is our table name so we will uh read all the records if i come here and if i show you this so this is this person person is our table name so i'll come again here now we have created our query so now i'll create sql command so is cable command cmd equals new cable command and here i'll pass in query and then con so now we have passed our qrin command so now i'll create this cable data reader this one reader equals dot execute reader and i'll put semicolon here now as we have created our reader now we will create um now we will read uh every records a record from this reader so this is uh showing an error because this is end execute reader so i to make it execute reader now it is good now we have to redo all the records where we will use while loop while uh reader dot read and now i'll put parentheses and now curly braces and here we will get all the values from our reader now if i go here to the table so we have three values id name and address so i'll go here and we will use a string output equals out output plus reader i'll use equality here equals reader dot get value zero dash that i need plus sign plus and uh here i need a plus sign and then double quotes inside double quotes i will use a dish plus reader dot git value and here i will pass in one and then plus double quotes and inside double quotes dash and then plus reader dot get value and i'll pass in two and now i'll put semicolon here so now why i pass 1 0 1 2 because we have only three columns 0 this p id becomes 0 name become 1 and two become this address become two so now we will show this output in our message box so message box dot show and here i will pass in uh out put and all output and i'll put semicolon here now we are good to go let's run the application and let's see if it is working so if i run this so now the application is running so if i click on this connect to excavate server so it has read the first record if i click ok second record third record and we have only three records here one two three so we have connected successfully to sql server and fetch data from this cable server and show in a message box 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: Programming Guru
Views: 39,671
Rating: undefined out of 5
Keywords: how to connect MSSQL SERVER in C#, c#, database, sql server, how to connect to sql server database in c#, How to connect Microsoft SQL Server in c#, connect sqlserver in c#, How to connect SQL server database with visual Studio C#, How to Connect SQL Server Database to C# app, How to connect C# to SQL, C# programming, Connecting to a SQL Server Database with C#, c# connect to sql server, visual studio, How to connect to sql server using C#, connect to sql database c#, yt:cc=on
Id: QUXiLfCtpHM
Channel Id: undefined
Length: 10min 41sec (641 seconds)
Published: Thu Mar 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.