Saturday, December 11, 2010

Displaying Data in Grid view Using ASP.Net With C # Coding

In Asp.net if we want to display the Emp table Data In Grid view

These are the lines of code we required to display in Grid view

add Namespeces

Using System.Data;
Using System.Data.SqlClient;


First we need Database connection here i took SqlServer for Data access

First we need establish the Sql Connection for that Create Object for Sql Connetion and also SqlAdapter

Sql Adapter Is Disconneted Model
which retrieve the data from database i.e. Sqlserver

Here ur Code
//Method for Display The Data In Grid View
Private Void GetData()
{
SqlConnectin MyCon=new SqlConnection("DataSource=YourDatasourceName; Intial Catalog=YourDatabseName; UserName=Sa;Password=yourPassword");

SqlAdapter MyAdapt=new SqlAdapter("select *from Emp",MyCon);

DataTable MyDt=new DataTable();

MyAdapt.Fill(MyDt);

GridView1.DataSource=Mydt;
GridView1.DataBind();
}

Call this method in Button Click or Page_Load u now able to view ur data on Gridview

Please provide correct Database Connection Credentials

Thanks Ur Umamaheswar

No comments:

Amazon.in


Don't Copy

Protected by Copyscape Online Plagiarism Checker

Pages

Offers