简体   繁体   中英

Adding row to datagrid in wpf using c# and display msaccess data in it

I am new to WPF and C# programming. I have created a form with some text boxes around 15. I have created a datagrid by the name of dgSearch and added 15 columns to it in xaml. Now the problem is how to add a new row to the dgSearch datagrid and display the data which is read from msaccess table in that datagrid. I am using WPF and C# with Visual Studio 2012. Kindly help me plzzz????

There are many different ways to get the data from the DB:

  1. Quick and Dirty. Just use the OdbcConnection and OdbcCommand and query for what you want. There are many examples out there just google them.

  2. Use LinqToSql and create objects based on your database.

Then to display the data in the grid it would depend if your using MVVM or not.

  1. Put the data in a DataSet and then bind it to the grid and it will automatically display and create your columns.

  2. Put the data in a collection like List, or ObservableCollection and bind that to your datagrid.

  3. Put it data in a any collection and then link to your control and insert, or use code to set the ItemsSource.

There are dozens of ways to do it, but you will need to define what approach you wish to take. I would strongly recommend you read about Data Binding in WPF, and perhaps Model-View-ViewModel before you decide. There are probably many examples that do exactly what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM