public partial class Form1 : Form { public Form1() { InitializeComponent(); BindGrid(); } private void BindGrid() { string constring = @"Data Source=.\SQL2005;Initial Catalog=Northwind;User id = sa;password=pass@123"; using (SqlConnection con = new SqlConnection(constring)) { using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", con)) { cmd.CommandType = CommandType.Text; using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { using (DataTable dt = new DataTable()) { sda.Fill(dt); dataGridView1.DataSource = dt; } } } } } }
//To Select Data from Customers Table var db = new DatabaseEntities(); var cstmrData = from c in db.Customers select c; //To fill grid dataGridView1.DataSource = cstmrData;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)