Skip to content
Advertisement

Execute query and populate the same in datagrid Box

I have a winform app connected to access database as data source ,

but in access i was using this below SQL to generate a query table called trend:

But i do not know how execute this & populate the same in datagrid box on form load event(dataset:CSCdataset) , please help me.

Advertisement

Answer

I guess you can find more information on your question here: How to query MS Access database with C# application? This post refers to the documentation: https://learn.microsoft.com/en-us/previous-versions/dotnet/articles/ms971485(v=msdn.10)?redirectedfrom=MSDN

In my winform-app, I use an SQL Server. It is probably somehow the same procedure for an Access database:

You can enhance this code by putting cnn into a using statement, like so:

Source: The C# using statement, SQL, and SqlConnection

To bind a DataTable to a DataGridView, just assign the DataTable to the DataSource Property of the DataGridView, like so:

I hope I helped you a little with my answer. Cheers

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement