Asp.net sql server database connection tutorial

Asp.net sql server database connection tutorial


hello friends now I am going to show you
how you can make insert update delete operation in asp.net so first of all
you can see I just opened this visual studio now I am going to make new
website I am going to show you from stretch so we are getting idea
here I am going to take asp.net empty website and just consider that we need
to select your visual C sharp now and I am going to create one folder then okay
now just we need to wait okay so here in solution Explorer we can
see we see it empty website that’s why we are getting nothing here so view->server explorer right click here then I’m going to do add new item then we need to select SQL
Server database Here I am going to you name is learning then add yes now we
need to wait okay so database is added now here in table right-click because we
are going to create a new table now in new table now here we need to give our table
name so I am going to write table name and it will take some time to load we need to give auto increments so that’s why right click property and now here I am going to new identity specification true now here I
am going to take post name I am going to take here we are here I am going to take
a last name and I am going to take here also we are here now we are going to
take city and here also varchar 50 now you can see we take all the
fields and we give autoincrement into ID now we are going to perform our update operation
so now we need to wait here we need to give update database
update complete so now we can see their table here
if we are getting table here then we need to check with your column is available or not yeah we are cheating so now I am going to close this okay now okay now rightly here then I am going to
add new item and we are going to take webform so select here web form and we
can give any name but default name is default.aspx so we are going to
take this now add so now we can see form in few
seconds yeah so now you can see we have this default page now now we are going
to take three textboxes, one for first name one for last name and one for
City so for this purpose we are going to take Table TR TD then table now I am going to write first name I am going to take second TD here
we are going to take textbox ID first name If you don’t want to write this code of
textbox then you can drag in proper so I am going to show you here I am
going to remove these textbox now I’m going to open this toolbox. okay sometime if you are getting full
width of this tool box than right click and make float so you are getting this
way now here I am going to take textbox so you are getting textbox and
then after we need to change order ID now I am going to take City and Here I am
going to take id as a City now I’m going to take one more TR then TD now I am
going to take colspan 2 and align Center and now we need three textboxes one
for insert one for delete and one for update and one for display one then I am
going to take copy paste paste paste yes Here I am going to take name insert then
delete then update and Here I am going to take view now after table I am going
to give one
and then after I am going to add gridview for display
record so first of all we are going to run this
simply and we are going to check that we get our proper layout or not then after we
are going to start our coding, when you are going to run your application first
time it will take some time to load, so, we have to wait okay so we are getting output proper so
now we can start our Code. so for coding for you need to go in design and Here I am going to double click on
this insert so we get here button on click event now when we have to do
database connectivity on that time, we need to add two libraries using system.data and using system.data.sqlclient here we need to make object now we need to
take database path from server explorer so open server server Explorer right-click on database then properties
then we need to select these connection string so I am going to copy these
and I am going to paste here, after paste,you need to remove this one up to APP data and here we need to add data directory the meaning of data directly
there’s you can see our database is stored inside this APP data folder so when
you are going to write your data directory it will take path up to this
APP data automatically so right now my data base in F Drive but later on if I
copy this folder and run from E drive then also it will work because it will
take path automatically that’s why now here we need to set some condition for connection state id as auto increment so we don’t
need to give anything now here we need to pass double quotes
double quotes so Pattern should be single double double single and in between we
need to pass plus sign now we are going to take firstname.Text now here we
are going to perform last name, you take and now we are going to perform City.text and after this insert Operation we
need to clean this texybox firstname.text=”” now here we
need to write lastname.text=”” and here we need to do city.text=”” so after completing this
directly insert operation, we need to display inside gridview, I am going to create your function function public void disp_data() oh yeah we don’t need to write function we are again we need to write SQL
command so I am going to copy this paste here and I am going to take Table one now here datatable dt and sql data adapter da now our display function is ready now we
need to call that function only here and we are going to call this function on
page load also so when our application load first time you can see all data
that’s why now I am going to run again we have to wait until it load yeah
so now I’m going to write here and now press insert pattern you can see a
record is inserted and textboxes are empty and we are getting our inserted record inside gridview so this way we can perform insert operation now we are
going to perform this delete operation delete operation we are going to delete
record using first name so if I am going to write the amit and when pressed
delete button this record should be deleted so for that again we need to
create the event of these second button so going here double click yeah we need
to copy this this 4 line is same everywhere I am going to paste here here
we need to write only delete from first ohh sorry delete from table1 where first
name is equal to single quotes in between double quote then plus plus sign and
now when you perform firstname.text so this way record should be deleted then after we
need to clean this firstname.text means out textbox is getting empty and then we need to display our record again going to call this display data function
so I am going to show you what output we are getting right now and then after we are going to perform
update oppression in last I am going to show you also why we are going to use a
single double double single I will show you that also okay all right now I’m going to write
here amit and press delete operation you can see their code is deleted and there
are no record available right now in table that’s why we can not see any
record inside gridview, you so now we are going to perform update operation so for
update operation we are going to update only first-name right now so we are
consider these first textbox for old firstname the second textbox for
new firstname and we can do one more thing also if you want to update using the ID
then we need to take one more textbox on that textbox what we are going to
perform ID we are going to write ID and then in these three textbox
we have to write our new record so on that ID we are going to update record, so yeah
let me take that new one so you are getting a great idea I am going to take after this part so I am going to take
here I am going to take here ID for update Here I am going to write old ID
so you get at exact idea now I am going to press from update here also we need
to copy and paste copy paste where we are going to pass here ID here we don’t
Need single quodes because our IDs integer that’s why and here we need to
pass old ID dot text and yeah we our IDs integer so we need to take here convert.toInt32 yeah now update table1 here we need to write a
set the first name is equal to lastname is equal to and city is equal to just
remember update query because 50% people are going to rejecting interview due to
these update query. write step-by-step so you are not getting any problem here I
am going to write firstname.text then I am going to write lastname.text
and then I am going to write City.text then after again we need to clean
three textboxes and display data so I am going to copy and paste here so now we are going to run a again and then we check
we get output or not okay so first of all we don’t have any
records I’m going to write this okay now insert and now you can see ID is 2
so I am going to write here ID and going to write of amit1, city rajkot
last name andipara and here I am going to take one and now I’m going to press update
operation you can see our record is updated so this way we can update your
record using ID if you don’t want to take ID and if you want to use these
three textboxes then you cannot update your old parameters because you
need one more textbox so this way we can update and
now view operation it is very easy because we’ve already created this function so here in
view operation we need to take only display data now if you don’t
want to use this type of function then what you need to do just remove this
function and copy this code and paste here nothing else the paste here so when
you are going to press button your old code executes but we create function
because after insert operation after delete operation after update operation
we need to display data so we don’t need to write this code again again that’s
why we create function so here we need to call this function only so this
way you can perform insert operation delete operation update operation, now I
am going to show you when we are going to execute query what happened so here I
am going to you comment and here this query I’m going to print response,.write
and in between I am going to write this query so we’ll get idea if this query
when we are going to run this query looks like same as MySQL SQL etc etc and so now I am going to right here only amit and going to perform delete Operation, you can see query build like
these delete from Table one your first name is equal to amit you can see these
the same query whatever you are going to write in mySQL SQL etc etc so that’s
why we are going to write this way now I am going to uncomment this code so
uncommon this code and going to delete this line so now finally we are going to
run and I am going to show you all operation so I hope you are getting a
whole idea regarding how you can perform insert update delete operation in
asp.net if you know how to perform this operation asp.net then by default you can
use this same code same query in C#.net also okay so I am going to take here second
record ABCD now insert you can see we are
getting this record now I’m going to delete this record record is deleted now
you need to update this record ID2 then we can write anything
our record is updated and we means we can display the record by default we are
going to display this so this way you can perform this asp.net all operation I
hope you are getting this thank you so much for watching my video if you like
my video then please like it and share it
thank you so much

Daniel Ostrander

Related Posts

8 thoughts on “Asp.net sql server database connection tutorial

  1. Aidaan Aziz says:

    Sir shoping website ka kuch aur details me bataye

  2. salman khan says:

    Sir plzzz send me the code

  3. Programming With Project says:

    sir thanks for making this video I know PHP but don't how to perform CRUD operation in asp.net but after watching this video with in half an hour I make small CRUD operation project thanks.I really appreciate your work.keep doing good work I am also a YouTuber u are inspiring very​ much.

  4. Zubair Khan says:

    Very nice Amit

  5. Zakarya Rkaa says:

    Great Mr.Amita

  6. Azim Lit. says:

    Great tutorial sir ! Could you make one, where such a CRUD operation is called from a Side bar or Dropdown menu ? I am trying to know how to implement a UI with Side bar(HTML and CSS) !!! Thank you again sir

  7. Jeremie Banza says:

    very good video

  8. Jai Gtz says:

    nice..simple..briefly.. easy to understand expecially for beginner.. thanks amit

Leave a Reply

Your email address will not be published. Required fields are marked *