Thursday 13 February 2014

display record from database(one tire)

your database like
    database name :student
    table name        :tbl_StudentData
    Field name         :id,name,age,gender,city,phone

Your .aspx page
------------------------------------------------------------------------------------------------

<div>
   <asp:GridView id="GridView1" runat="server">
   </asp:Gridview>
</div>


--> your .aspx.cs file

--> if you want to display record from table or database that time add following namespace in your code behind file
------------------------------------------------------------------------------------------------



using System.Data;
using System.Data.SqlClient;


--> and then create following  object  above page load event
------------------------------------------------------------------------------------------------

  

    SqlConnection cn;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;

--> next assign the connection string in page laod event
------------------------------------------------------------------------------------------------



cn = new SqlConnection(@"DataSource=\student.mdf;Integrated Security=True;User Instance=True");



--> and then write following code in your code behind on page load event
------------------------------------------------------------------------------------------------

   

 cmd = new SqlCommand("select * from tbl_StudentData", cn);
        da = new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;   //give dataset to gridview
        GridView1.DataBind();         // binding gridview

No comments:

Post a Comment



Asp.net tutorials