Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I use C# WPF, I am programming an accounting program with a SQL Server database, in this accounting program, data is inserted, updated, and deleted by the user directly in a data grid, which contains a textbox and Combobox elements.

In an issue that I was very confused about, which method of connecting to the database and storing data through the data grid is better?

What I have tried:

ADO.NET with DataSet and TableAdapter like this :

private void LoadData()
       nOTELBOOKDBDataSet = ((SIMPLE_MVVM.NOTELBOOKDBDataSet)(this.FindResource("nOTELBOOKDBDataSet")));
       // Load data into the table PERSONEL. You can modify this code as needed.
       nOTELBOOKDBDataSetPERSONELTableAdapter = new SIMPLE_MVVM.NOTELBOOKDBDataSetTableAdapters.PERSONELTableAdapter();
       System.Windows.Data.CollectionViewSource pERSONELViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("pERSONELViewSource")));
   void SaveData()
       NOTELBOOKDBDataSet changes = (NOTELBOOKDBDataSet)nOTELBOOKDBDataSet.GetChanges();
       if (changes != null)
           //Data has changes.
           //use update method in the adapter. it should update your datasource
           int updatedRows = nOTELBOOKDBDataSetPERSONELTableAdapter.Update(changes);

The second case:

public void LoadData()
       using (DataModeling.Entities dbms = new DataModeling.Entities())
           var RES = dbms.Database.SqlQuery<HUMANS_TBMODEL>("SELECT ID,NAME,TEL,REMARKS FROM PERSONEL").ToList();
           foreach (var item in RES)

Please guide me which is the best and easiest way?
Updated 7-Jan-23 13:39pm

1 solution

Databinding with data models bound to the DataGrid. EntityFramework or Dapr is a cleaner and simpler database framework. There are plenty of Google searchable tutorials explaining how to do both.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900