How to use DataGrid in C# .Net?

First place the DataGridView Control in the form.In the coding add the namespasce

using System.Data.SqlClient;

then initialize SqlConnection to ConnString as public (i.e)next to public Form1( ) {InitializeComponent( );}

SqlConnection con = new SqlConnection(“Your Connection String”);

DataSet ds;

Inside any event such as Form_load or button1_click add the code

SqlDataAdapter da=new SqlDataAdapter(“select * from table1”,con);

ds=new DataSet();

da.Fill(ds,”table1″);

dataGridView1.DataSource=ds;

dataGridView1.DataMember=”table1″;

By

Udhaya

Advertisements

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: