Bind Dataset to DataGridView C#
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.
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).
Step 3: After selecting data source option select “Add Project Data Source…”
Step 4: Select Database option and click button “Next” as below image.
Step 5: Now select “Dataset” option and move next step as below image.
Step 6: Here we create new connection for database connectivity. Click on button “New Connection” as below image.
Step 7: A new wizard “Add Connection” is display. See below image and read content according assign point.
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.
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.
Step 9: Here you save you connection. And click button “Next”.
Step 10: In this step select table and column according your requirement (1). Give DataSet name (2) and click button “Finish” (3).
Step 11: Adjust height and width of datagridview and save application and execute. My demo screen shot given below.