articles

Home / DeveloperSection / Articles / Bind Dataset to DataGridView C#

Bind Dataset to DataGridView C#

AVADHESH PATEL27568 08-Jan-2013

In this article I’m going to explain, how to bind an existing database table items to datagridview.  Here I’ve define some steps which are necessary to perform this task.

Step 1: First of all you’ve to create a windows form if you’re using Visual Studio application then you can simply drag and drop DataGridView control from toolbox which I’ve shown you below.

Bind Dataset to DataGridView C#

If you want to add, edit and delete datagridview column then enable this option in datagridview which I have shown in above image.

Step 2: “Select Data Source” from combobox (red circle in below image).

Bind Dataset to DataGridView C#

Step 3: After selecting data source option select “Add Project Data Source…”

Bind Dataset to DataGridView C#

 

Step 4: Select Database option and click button “Next” as below image.

Bind Dataset to DataGridView C#

Step 5: Now select “Dataset” option and move next step as below image.

Bind Dataset to DataGridView C#

Step 6: Here we create new connection for database connectivity. Click on button “New Connection” as below image.

Bind Dataset to DataGridView C#

Step 7: A new wizard “Add Connection” is display. See below image and read content according assign point. 

Bind Dataset to DataGridView C#

 1.       Here you set “Server Name”. For example xyz\SQLExpress or .\SQLExpress.

2.       If your database is SQL Server Authentication than it required that user name and password.

3.       In Connect to a database section you have given database. For example my database name is myDatabase. Otherwise you select Windows Authentication.

4.       If server name, user name, password and database name are correct than it display a confirmation message box as below image.

Bind Dataset to DataGridView C#

  5.       Now press button OK and move next step.

Step 8: Here you see (below image). 1 represent new connection name. 2 represent connection string and 3 move for next step.

Bind Dataset to DataGridView C#

  Step 9: Here you save you connection. And click button “Next”.

Bind Dataset to DataGridView C#

Step 10: In this step select table and column according your requirement (1). Give DataSet name (2) and click button “Finish” (3).

Bind Dataset to DataGridView C#

Step 11: Adjust height and width of datagridview and save application and execute. My demo screen shot given below.

Bind Dataset to DataGridView C#



Updated 10-Jul-2020
Avadhesh Kumar Patel District Project Manager - Aligarh 14 months work experience in Panchayati Raj Department Sector as District Project Manager & 12 months work experience in IT Sector as Software Engineer. :-)

Leave Comment

Comments

Liked By