using System.Data;
using System.Data.SqlClient;
//Use all These Libararies If Your Connecting SqlServer
//Write These Codes In A Button Click Event Or A Function Or What Ever Event You Want To
#region Codes
string ConnectionString = @"Server=localhost;Database=dbName;Trusted_Connection=True";
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
DataTable dt = new DataTable(); // create a virtual table
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM TestTable , connection);
// create a data apadter. i have used sql..
sda.Fill(dt);//load the result from Data Adapter to the Virtual Table
datagridname.DataSource = dt; //add the virtual table to the datagrid.
#endregion