Click here to Skip to main content
15,848,758 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 :

C#
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();
       nOTELBOOKDBDataSetPERSONELTableAdapter.Fill(nOTELBOOKDBDataSet.PERSONEL);
       System.Windows.Data.CollectionViewSource pERSONELViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("pERSONELViewSource")));
       pERSONELViewSource.View.MoveCurrentToFirst();
   }
   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);
           nOTELBOOKDBDataSet.AcceptChanges();
       }
   }


The second case:

C#
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)
           {
               MY_ALL_HUMANS.Add(item);
           }
       }
   }


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

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