How To: Bind data from Sql Server to dataGridView
DataGridView displays the contents of a data source. It is a control in Windows Forms. It uses a grid format. There are many ways to improve its default configuration. We show some improvements to usability and appearance.
DataGridView displays the contents of a data source. It is a control in Windows Forms. It uses a grid format. There are many ways to improve its default configuration. We show some improvements to usability and appearance.
DataTable GetData(){ DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString)) { con.Open(); using (SqlCommand cmd = new SqlCommand("select Name from SampleTable ", con)) { SqlDataAdapter adpt = new SqlDataAdapter(cmd); adpt.Fill(dt); } } return dt; }
Call this function anywhere
Related Post :