Ad Code

DataGridView in C#

Also Read

DataGridView in C#

The DataGridView control displays data in a customizable table. The DataGridView control allows you to display and edit tabular data from a variety of data sources. Cells, rows, columns, and borders in the DataGridView class can be customized using properties such as DefaultCellStyle, CellBorderStyle, GridColor, and ColumnHeadersDefaultCellStyle.

A DataGridView control can be used to display data with or without an underlying data source. You can create data-filled columns and rows and add them directly to the DataGridView using the Rows and Columns properties without specifying a data source.

DataGridView in C#


In today's article we will learn how we can add data in DataGridView with the help of data source. I am using visual studio 2017 here, you can use any version.

STEP 1. First, create the windows form project in Visual Studio.



STEP 2. When you create the project, you will have a form like this. Now drag and drop the DataGridView control from the toolbox something like you can see in the image.



STEP 3. Now right click on DataGridView and here you will get an option of choose data source click on it and click on add project data source.



STEP 4. Select the database option here and click Next.



STEP 5. Click on new connection.



STEP 6. Enter the name of your database server in server name. If you do not know the name of your server, you can open SQL Server Management Studio and see the name of your server. After writing the name of the server, select your database and then click on OK.





STEP 8. Now select the table whose data you want to show in the DataGridView and then click on finish.



STEP 9. Now you can see that the data source has been created successfully.



STEP 10. Now compile the program, all the data that was stored in the table in the backend will be shown in the DataGridView.


If any issue comes to you even after that, you can comment to us or you can watch a video on this topic on our YouTube channel.

Post a Comment

0 Comments

Ad Code