Excellent tutorial, very clear and concise. While running tests, pressing the Update Button while TextBlock fields are empty (prior to any data going in them), the if statements conditions fail to prevent execution and throws an exception. Swapping the conditions e.g. (name != null ) to (!String.IsNullOrWhiteSpace(name) ) resolves this issue. Hopefully this is of use to someone.
I'm super happy to have run across this in my search for C# CRUD with SQLite... not only is it a great start for the entity framework, but you also taught me a few things about WPF and binding and a few other little helpful things. Nice.
This video is absolute gold.. I'm 100% new to C# and xaml, and I'm trying to build a point of sales system for my dad's friend's business. For about a week now I've been trying to figure out how to work with sqlite and how c# and xaml relate to the database... This video has answered every single question i had and then some that i would've ended up asking later down the road... you, sir, are a god send
32:24 to clear the database: private void MenuItem_Click(object sender, RoutedEventArgs e) { using (DataContext context = new DataContext()) { var allUsers = context.Users.ToList(); context.Users.RemoveRange(allUsers); context.SaveChanges(); } }to clear the database:
Hi, and thanks for all. I want to tell You that for me (Visual Studio 2022) has been impossible download the default entity.sqlite package. But choosing an older version (3.1.22), the download has been accepted and is working.
Hi, I wanted to thank you for this video lesson and also have a question. Has anyone encountered the problem of missing e_sqlite3.dll on Win11 VS22. Since I downloaded sqlite through NuGet packages, and when the error occurred, I also downloaded it through the official site. If there are mistakes in the text, sorry, I'm from Ukraine, I do not know your language.
If sqlite3.dll is missing It means visual studio could not download the library that’s, why it’s important to use nuget package manager in visual studio it will help you manage the DLL files of your project and remember to type in the correct name of the package because there are so many packages with similar names,
Thank you very much, I haven't watched the video yet, but it helped me in the beginning with my knowledge of data bindings, and I'm sure it will help with databases too.
Thank you a lot! I've been struggling to find information about CRUD (without all this select * and etc). but your channel and the way you explain it's just priceless! thank you for your time and efforts!
Hello Sir, I liked this video. can you make a WPF course or video series on WPF/MSSQL for something like a POS or for an APPOINTMENT system, where users have to login first and according the user's role he/she do tasks. Thank you very much & keep up the good work.
The video is good. It's just a bit silly that you didn't use the update function immediately after creating a new data set. That would have been more intuitive. That the ListView is reloaded immediately when a record is created. Ich habe den Code etwas verbessert. So ist er funktionaler. public MainWindow() { InitializeComponent(); Read(); } public void Create() { using (DataContext context = new DataContext()) { var name = NameTextBox.Text; var adresse = AdressTextBox.Text; if (Name != null && Adresse != null) { context.Users.Add(new User() { Name = name, Adresse = address }); context.SaveChanges(); } } Read(); NameTextBox.Text = ""; AdresseTextBox.Text = ""; }
@@TacticDevs Ah ok. But I have now noticed something else in my case that can also lead to mistakes for others who are about to start. The Nuget package EntityFrameworkCore.Sqlite is only compatible with the new .Net standard WPF project. Not to the .Net Framework WPF. There is already an error when installing the Nuget package, when I built it. But I also didn't pay attention to whether you had previously mentioned which project template you were using. I just wanted to let you know if someone builds this and gets this error.
You can add another DbSet property the to the Dbcontext class the DbSet Property represents a database table, the more you add more database tables you will have
You need to make sure that the connection string is correct and make sure that the name of the DBset property in the context class is the same as the table name
As well as do not forget to use the Facade class that is found in entity framework infrastructure namespace use this class to ensure that the database file is created when the application starts up,have a look at 11:55
I tried using only the create method to input details into the database, but this exception wan thrown: SqliteException: Microsoft.EntityFrameworkCore.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.' SQLite Error 19: 'NOT NULL constraint failed: Users.Id'. Any tips?
it seems you tried to write a null value to the id property, the other issue might be that you named the the User class ""Users"" ,Entity frame will also name the table "Users" this might cause a name conflict so you can remove the "s"
Hi Tactic Devs, thank you very much for your helpful tutorial. Once I run the app and hit the create button, the db file doesn't create. What might the reason be? Cheers, Federica
The DB file is created during the start up process of the application, This is done by calling the ensurecreated method from the database façade class, Check the App.cs and Verify the code 11:55 Or 14:03, However if the DB file is already created it means The problem occurs when you try to create an entry in the database it’s means should verify the create method that was defined in the mainwindow class 15:43
@@TacticDevs the ensurecreated method always returns false. It seems like the database has already been created even if it's not cause when i look for it in the bin directory i can't find it. Can I check out anything else?
I understand that , however this video is about how to communicate with a database rather than focusing on project structuring or adhering to SOLID principles. thats for a separate video
Why? This is SQLite, not some enterprise SQL server. I'm using SQLite for local storage, user interface and project settings, not some enterprise database with private user data. No reason to be so rigid.