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")));
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)
{
int updatedRows = nOTELBOOKDBDataSetPERSONELTableAdapter.Update(changes);
nOTELBOOKDBDataSet.AcceptChanges();
}
}
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)
{
MY_ALL_HUMANS.Add(item);
}
}
}
Please guide me which is the best and easiest way?