Good evening,
I am a beginner at MVVM design patter and WPF I am trying to make a small example of connection to the MS Access database using the WPF and MVVM Light Toolkit patter design. here is the code I insert for the connection:
Model / DataConnection.cs
- public class DataConnection
- {
- public void OpenConnection()
- {
- OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb;" +
- "Persist Security Info=False;");
-
-
- OleDbCommand cmd = con.CreateCommand();
- cmd.CommandText = "Insert into table (num,nom)Values(123,'nom1')";
- cmd.Connection = con;
- con.Open();
- cmd.ExecuteNonQuery();
- MessageBox.Show("Record Submitted", "Congrats");
- }
- }
ViewModel / MainViewModel.cs
- public class MainViewModel : ViewModelBase
- {
- private DataConnection _dataconnection;
- public MainViewModel(DataConnection dataconnexion)
- {
- _dataconnection = dataconnexion;
- _dataconnection.OpenConnection();
-
- }
- }
ViewModel / ViewModelLocator.cs
- public class ViewModelLocator
- {
- static ViewModelLocator()
- {
- ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
- SimpleIoc.Default.Register<DataConnection>();
- SimpleIoc.Default.Register<MainViewModel>();
- }
- public MainViewModel Main
- {
- get
- {
- return ServiceLocator.Current.GetInstance<MainViewModel>();
- }
- }
-
-
-
-
- public static void Cleanup()
- {
- }
- }
when i run the program it does not do anything and when i debug i find that the instruction stops at the instruction level
model / DataConnection.cs file and then it goes to MainWindow.xaml.cs.
I do not find why he does not continue the execution of all the instructions?