Home > DeveloperSection > Forums > DataGridView Binding - SQL Server dataset in C#
Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    June-15-2013 4:46 AM

 C# C# 

 1 Reply(s)
 1345  View(s)
Rate this:
hi Developers,

How to bind the DataGridView with SQL Server dataset in C#.

Sumit Kesarwani

Total Post:378

Posted on    June-15-2013 7:42 AM

Hi Takeshi,

You can use this code:

using System;

using System.Data;

using System.Windows.Forms;

using System.Data.SqlClient;


namespace WindowsApplication1


    public partial class Form1 : Form


        public Form1()





        private void button1_Click(object sender, EventArgs e)


            string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True";

            string sql = "SELECT * FROM Authors";

            SqlConnection connection = new SqlConnection(connectionString);

            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);

            DataSet ds = new DataSet();


            dataadapter.Fill(ds, "Authors_table");


            dataGridView1.DataSource = ds;

            dataGridView1.DataMember = "Authors_table";




Don't want to miss updates? Please click the below button!

Follow MindStick