Monday 16 September 2013

Data GridView Control in .net

GridView control is used in .net for displaying the data in webpage from the database.
it is used to interact with the database from the asp page....

first of all make the database in sql server....
i make database name "vaibhav" in which i created table name"item"

take one web application and place gridview control on that webpage.  like this

now we have to connect the database with the webpage...
Open the server explorer and right click on Data Connection  then click on Add Connection. like this



you will get this window...in this window enter the server name and select your database...then click on Test Connection .if you done all things correctly it display the message box Connection Successfully added.
then click on OK.

now your data will be displaying in server explorer.

right click on it and open the properties of your database and copy the connection string.
displaying in the pic.


now you get your connection string and go to your code window..
write the below code..

in this code....
1)add the namespaces System.DATA and System.DATA.SQL.
2)make the connection by using sqlconnection class.we also pass the connection string as a parameter at the time of object creation.which connect the database with the asp page.
3)make the object of sqldataadapter in which we pass the sql command and the connection object name
4)create the object of dataset provide virtual table.
5)we provide the data source to grid view
6)bind the data with the grid view in last statement.
now open the code window by double click on the design window and write the code......

run the application you will get
you will get same table as you created in database ....

for inserting the data take 1 button and 3 textboxes because we have 3 columns in the table ..write the code...



for Updating..
take 1 button and write the code...


we update the itemname and price column by giving the id in a where clause...

after clicking on update button it updates the value in id =1.
you can see this changes in the table.




2 comments :

  1. Do you know how many articles in your website are a true copy paste from other's blog.

    Stop publishing such content before a legal person contacts you !!

    I am from the US and write original content. People like you are a shame.

    If you are a reader, don't read this blog.

    ReplyDelete
    Replies
    1. Hahahaha .....bro these are the original contents written by me...i know you all are feeling jealous because i wrote the topics in a easiest way if these topics are copied by me then paste the link here from where you think i copied the data......and all peoples who read this blog check those links .......blaming the person is the easiest thing in the world...........

      Delete