Create Login in WPF, MVVM Pattern, C# and SQL Server - Step by Step + Display user data

Sdílet
Vložit
  • čas přidán 7. 07. 2024
  • ⏮️ Previous Video: WPF UI/ Design a Modern Login Form/ Introducing to WPF
    • WPF UI/ Design a Moder...
    ⏭️ Next Video: WPF & MVVM/ Modern Main UI Design
    • WPF & MVVM/ Modern Mai...
    🎞️ Hi, in this tutorial we will learn how to Create Login Form in WPF, MVVM Pattern, C# and SQL Server, additionally we will display the data of the current user in the main window.
    Content:
    00:00 Introduction to MVVM
    02:18 Database
    02:53 Implement View Models
    03:25 ViewModel Base Class (INotifyPropertyChanged)
    04:20 ViewModel Command Class (ICommand)
    06:33 Login ViewModel Class
    11:44 Set Binding between the View & ViewModel
    13:49 Create a Bindable PasswordBox (Dependency Property)
    19:50 Implement Models
    20:33 Implement Data Access Objects
    26:28 Register the user in the Thread
    27:33 Configure Application Startup
    30:19 Retrieve and Display user data (Again using MVVM)
    ⬇️ DOWNLOAD PROJECT
    rjcodeadvance.com/inicio-de-s...
    📲 Social Media:
    Facebook: / rjcodeadvanceen
    Instagram: / rjcodeadvanceen
    Website: rjcodeadvance.com
    #WPF #MVVM #LoginForm #SQL #ModernForm #modernui #design #CSharp #VisualBasic #VB.NET #VisualStudio #Custom #Chart #FlatUI #Desktop

Komentáře • 82

  • @kunleth
    @kunleth Před rokem +6

    I truly appreciate you ... this is an awesome tutorial. And breaking down the MVVM principles like this is golden. Thank you.

  • @Your_Better_You
    @Your_Better_You Před rokem +7

    Just started developing using WPF, your tutorials really helped me a lot 👍👍👍
    Just wanted to share @ 25:22
    Instead of writing : validUser = command.ExecuteScalar() == null ? false : true;
    I used : validUser = command.ExecuteScalaer() != null;

  • @entemolu1
    @entemolu1 Před 2 lety +4

    Learn from an expert. Wonderful tutorials for professional also

  • @ghelonicomaligaya3232
    @ghelonicomaligaya3232 Před 2 lety +1

    Finally! Thank you for this.

  • @user-zp1po5us1e
    @user-zp1po5us1e Před rokem

    thank you for the great video!

  • @hasanmougharbel8030
    @hasanmougharbel8030 Před rokem +2

    I feel blessed learning from this channel. I have simply a general enquiry as a newbie sql learner.
    I realized recently that i may need to write in languages other than sql on the database engine, like, python, C#
    What is the best practice to integrate several languages inside the same database management software.
    Should i look forward to a particular text editor or is there other features that may facilitate multi-language integrations inside database system.

  • @minoubrc4773
    @minoubrc4773 Před 9 měsíci

    Really well explained

  • @sirinebibicha2024
    @sirinebibicha2024 Před rokem

    Great video .. Thank you👌

  • @inhnguyen-zq6tq
    @inhnguyen-zq6tq Před 2 lety +1

    Magic !

  • @ilianabenchikh9330
    @ilianabenchikh9330 Před rokem +1

    I'm a french student in IT and your tuto helped me so much, tank you !!

    • @FrenzyNull
      @FrenzyNull Před rokem

      tank you too for the nice comment

    • @StrawHatGyro
      @StrawHatGyro Před 9 měsíci +1

      I am student too, in the netherlands. Good luck in your studies, frenchie!

    • @DirePantsDim
      @DirePantsDim Před 9 měsíci

      Good luck! :)

  • @bennzzen86
    @bennzzen86 Před rokem

    Thank You, Adblocker

  • @MrJuche23
    @MrJuche23 Před rokem +1

    Please keep going with this series. you videos are some of the best out there. Thank you

  • @son1powa
    @son1powa Před 10 měsíci +1

    First of all thanks for your given time for this tutorial.
    I'm developper since 8 years now and MVVM seems so much complicated and so many things to add and re add etc i'm a little lost with so many classes.
    Juste for asking, why don't you use Datasets to interact with the SQL ?
    you create the same object to be as the database is but you only have 4 fileds is it worth it with a complete database in real life ?

  • @easylearning-8153
    @easylearning-8153 Před 9 měsíci

    Thank u

  • @robertorinaldi977
    @robertorinaldi977 Před 11 měsíci +2

    Great video, I learned a lot from it!
    However, I noticed that there is a problem on the login View.
    If you run the app and click close without logging in, an exception will be thrown. How to solve it?

  • @user-ry8we7iy5r
    @user-ry8we7iy5r Před rokem

    Hi. Your video is just amazing. But if I did everything in one window? That is, from the authorization UserControl I can open the UserControl
    registration or UserControl navigation menu depending on what the user will do in UserControl authorization. How to implement it?

  • @janslanina2209
    @janslanina2209 Před 2 lety

    Aw, you jumped on WPF, guess Ill need to catch up on you when I learn more of windows forms. :)

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Před 2 lety +1

      Thanks for watching my videos, well the only difference between WPF and WinForms is the way you design the UI (C# Only - XAML & C#), however everything else is the same :)

    • @entemolu1
      @entemolu1 Před 2 lety

      @@RJCodeAdvanceEN what about the animation , storyboard

    • @janslanina2209
      @janslanina2209 Před 2 lety

      @@RJCodeAdvanceEN You mean to tell me if I follow the backend code it will work as well ? :O

  • @josaphatkayombo9057
    @josaphatkayombo9057 Před rokem

    Great videos sir !!!
    please can teach us how to deploy a winforms app in local area network(LAN)? thanks...

  • @ZacharyRodney
    @ZacharyRodney Před rokem

    excellent video. the best I've found so far for practical project walkthroughs that include best practices. I followed along without issue and at the end I'm finding an issue that is hard to debug. the login command is not triggering the "username or password is incorrect" or the view change event. hard to debug. I understand what is happening in the code, but not sure how to correct it. any suggestions?

    • @Aiden-lu3vj
      @Aiden-lu3vj Před rokem

      do u know where u can make an username and password

  • @Elta305
    @Elta305 Před rokem

    Does someone know how to create a sql server ? I have an error when I try to connect to my database

  • @wsilvawgt
    @wsilvawgt Před 2 měsíci

    Could you help how to create user roles and privileges?
    as an administrator, access to everything
    managing member with access to everything but the administrator can modify something
    and Ordinance with access to everything else the administrator will modify manually.

  • @huihui7477
    @huihui7477 Před 6 měsíci

    "Hello, I recently came across your videos on C-Sharp WPF tutorials. I'd like to ask, should I start watching from the MVVM playlist, or from the WPF playlist?"

  • @tuannguyenvanquoc2670

    i cannot connect to my sql, my name sever is SQLEXPRESS so _connectionString = @"Server=SQLEXPRESS; Database=MVVMLoginDb; Integrated Security=True".Is that right?

  • @t3hPoundcake
    @t3hPoundcake Před rokem +1

    31:55
    Isn't the System Threading Principal class for the user who is logged into a local machine (or I guess a remote machine possibly)? I'm confused as to why we are using that to pass the username parameter to GetByUsername() instead of what the user types into the Username field and then displaying another error if there is not a username in the table with that string, because on another video I posted about how closing the window from the login form displays a break in the code and it is with this Generic Principal implementation that is causing the null reference exception.
    Have you encountered this error? Do you have any idea how I can fix or would it be better to try and pass the username that is typed into the field as the parameter?

  • @wsilvawgt
    @wsilvawgt Před 2 měsíci

    Could you help me to synchronize with SQL Server Management Studio in WPF, MVVM Pattern, C#
    I can't, I created the same form as you, I modified it my way but I can't connect to SQL Server Management

  • @edence6001
    @edence6001 Před rokem +4

    Если ты это смотришь и ты такой же тупой как и я,то в строке подключения к бдэшке нужно два слэша,и посмотри на метанит как выглядит подключение

  • @deakattila
    @deakattila Před 10 měsíci

    what If I want to use a command parameter? how can I do that?

  • @jatinkamble7720
    @jatinkamble7720 Před rokem

    System.Data.OleDb.OleDbException: 'Must declare the scalar variable "@username".' how to connect

  • @SirLuke33
    @SirLuke33 Před 6 měsíci

    I've done several tests and I'm not sure if it's the right method. If anyone wants, they can correct me. I use wpf core 8
    from: _connectionString = "Server=(local); Database=MVVMLoginDb; Integrated Security=true";
    to: _connectionString = "Server=(local); Data Source=(localdb)\\MSSQLLocalDB; Database=MVVMLoginDb; Integrated Security=true";
    On a remote server I have no idea how to do it. I'm just starting out.
    Then I made this change.
    Id = reader[0].ToString();
    From an error. I noticed that integers are not generated in the db. The error is that it cannot be converted from int to string. I put a cast (int) and it throws an error. Removing id, it works. I don't know how to change this.

  • @kumarabhishekranjan4694
    @kumarabhishekranjan4694 Před 9 měsíci

    This code is not fetching and displaying data on the screen. Where can I check this for fix. Any kind of help is appreciated.

  • @miyano2544
    @miyano2544 Před 2 lety

    It's what I'm looking. Thank you! Also I'm wondering; It's possible OAuth2 login system using Google/Discord API? I Searched too long but i didn't find anything... Can you give me a referance or advice?

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Před 2 lety +1

      Hi thanks.
      Well, honestly, I haven't, but it's possible. uses Google APIs.
      "The library supports OAuth2.0 authentication. Strongly-typed per-API libraries are generated using Google's Discovery API."
      www.nuget.org/profiles/google-apis-packages

    • @miyano2544
      @miyano2544 Před 2 lety

      @@RJCodeAdvanceEN Thank you for answer! I'll look that library. I hope I can also find a way for Discord OAuth2. Love you and your content!

    • @Aiden-lu3vj
      @Aiden-lu3vj Před rokem

      @@miyano2544 do u know where u can make an username and password

  • @daliangilbert
    @daliangilbert Před rokem +1

    I really wondering what is wrong with the code:
    if (loginView.IsVisible == false && loginView.IsLoaded)
    {
    var mainView = new MainView();
    mainView.Show();
    loginView.Close();
    }
    because when I tried to use it exactly the same as in this tutorial and try to close login window - loginView.IsLoaded becomes true and loginView.IsVisible becomes false what raises an error "Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing". Does somebody know why?

    • @thanderstaff9593
      @thanderstaff9593 Před rokem

      have you found a solution to the problem?

    • @Den-Irenicus
      @Den-Irenicus Před rokem

      The author forgot to show how renamed MainWindow.xaml to MainView.xaml. Just rename it and dont forget to fix MainView.xaml.cs. And this problem could be fixed by changing Target Framework to .NET Framework 4.8 (from .NET Core)

    • @BreezElly
      @BreezElly Před rokem

      @@thanderstaff9593 Not sure if it's correct solution but instead of line "loginView.Close();" i used "loginView.Visibility = Visibility.Hidden;" and it worked just fine.

    • @Xodocl
      @Xodocl Před 10 měsíci

      @@thanderstaff9593 You can add this condition:
      if (Current.ShutdownMode == ShutdownMode.OnExplicitShutdown)
      return;
      before the first. You also need to add this line in the LoginView codebehind in the "btnClose_Click" event handler:
      "Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;" before calling the Shutdown() method.
      This is the first thing that came to mind :)

  • @thaithanhloc6791
    @thaithanhloc6791 Před rokem

    can you make more videos with mongodb

  • @tesladude2822
    @tesladude2822 Před rokem +1

    After creating BindablePasswordBox I start having error on InitializeComponent: 'A 'Binding' cannot be set on the 'Password' property of type 'BindablePasswordBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject'. Compared the code and cannot find the error. Please help.

    • @nirnafrin4707
      @nirnafrin4707 Před rokem

      its happend to me too you have the solution?

    • @tesladude2822
      @tesladude2822 Před rokem

      @@nirnafrin4707 It is embarrassing, but I found that I just made a typo in the word Password (three S :)) .

  • @mplaimer
    @mplaimer Před rokem

    Great video series but I had one problem in my project.
    14:45 your path for the image doesn´t worked for me. I found 2 other workarounds. pack:\\application:,,,/Images\key-icon.png or ..\Images\key_icon.png.
    This worked for me at Designtime and Runtime! Before, I had an error in the XAML Designer, but the icon was displayed correctly at runtime.
    Maybe someone else has this problem.

    • @Aiden-lu3vj
      @Aiden-lu3vj Před rokem

      do u know where u can make an username and password

    • @wamique
      @wamique Před rokem

      I am having this issue. Did you find the solution? Please help.

    • @mplaimer
      @mplaimer Před rokem

      @@wamique Hello, yes I found a workaround for the problem. I have already written it above, but here again.
      pack:\\application:.../Images\key-icon.png or ..\Images\key_icon.png.
      In my Xaml-Code I use
      ImageSource="..\..\Views\Images\key_icon.png"
      and also
      ImageSource="../Images/user_icon.png"

  • @doannam5900
    @doannam5900 Před rokem

    At 30:10 when I tried to Execute, after I clicked Login, it throw an exception that 'Cannot open database "MVVMLoginDb" requested by the login. The login failed.'. How can I fix that? I hope to recive your help! Thanks for tutorial

    • @Elta305
      @Elta305 Před rokem

      Did you find an answer ? I have the same issue, I think it's because we need to create a sql server but idk how to do

    • @rasmuse2713
      @rasmuse2713 Před rokem

      @@Elta305 Of course you need to set up a database on either MS Sql Server or MySql and create a database called "MVVMLoginDb". His database is not public. MySQL is free. And in his video he shows an SQL script that will create the database and table for you: 2:20

  • @kylechesshir7681
    @kylechesshir7681 Před 16 dny

    Has anyone had any luck contacting the content creator? I'd really like to get info on why I keep getting a "System.NotImplementedException" at the 30 min. 10 sec. mark.

  • @kopch1k82
    @kopch1k82 Před 2 lety

    what about security? like hwid-protect and anti-dump

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Před 2 lety

      there is no complete way to avoid memory dumps. Obfuscators are also easy to obfuscate.
      What I do is obfuscate the code manually and make life difficult for those who try to decompile my project, when I finish a project I rename everything, such as: namespaces, classes, properties, fields, methods, etc.
      I put any long name, example: fagerge78er78ge4gea9g4aeg
      Although that takes me a long time.

    • @kopch1k82
      @kopch1k82 Před 2 lety

      @@RJCodeAdvanceEN you can make name space: jmp 20491mp
      dumpers can think it's jump to a code

  • @xibble4320
    @xibble4320 Před rokem +1

    How do I make and use the database?

    • @carapysca1238
      @carapysca1238 Před rokem

      Open server exlorer in VS. Then connect to your database. If you dont see your server name insert any of this: . , local, (local)/SQLEXPRESS. Then cooy connection string from properties

  • @Dysonator
    @Dysonator Před 17 dny

    This code is not checked in to github.

  • @GalaxyTJ
    @GalaxyTJ Před rokem

    I get a error with the sql server i cant connect.

    • @Den-Irenicus
      @Den-Irenicus Před rokem +2

      I had the same problem. I changed in Repository.cs _connectionString to "Server=(local)\\SQLExpress; Database=MVVMLoginDb; Integrated Security=true";

    • @jedit2586
      @jedit2586 Před 10 měsíci +1

      @@Den-Irenicus Hey there, just wanted to say THANKYOU SO MUCH 🙏. I was stuck on this problem for a whole day and couldn't work out what went wrong 😭. Good thing Ifound your comment!

    • @SirLuke33
      @SirLuke33 Před 6 měsíci +1

      @@Den-Irenicus HI. I use core 8 and I also get the connection error. I'm just starting out and I still can't fix it. I searched the web for a solution, nothing.
      thank you so much for your help

  • @Fayritail1337
    @Fayritail1337 Před rokem +1

    the previous video was way better this one is more confusing than helpful you start just by assuming people know hot to do the database instead of showing them and hot to implement it is confusing if you gonna start SQL video show how to do the database and next hot to build the code

    • @exogendesign4582
      @exogendesign4582 Před rokem

      Actually I can create app in c# but watching his style really confuse me, I can follow along and make it work but the problem is I don't understand a damn thing on what I was doing specially Interface, it hurts my brain so I am relearning everything. You should start small too since SQL the easiest thing to do. His Tutorial aren't for begineers but advance C# user.
      Learn about design pattern, Dependency Injection Principle, Interface Segregation Principle, MASTER OOP too then you can get the gist of what his talking.

    • @Aiden-lu3vj
      @Aiden-lu3vj Před rokem

      @@exogendesign4582do u know where u can make an username and password

    • @Aiden-lu3vj
      @Aiden-lu3vj Před rokem

      do u know where u can make an username and password

    • @exogendesign4582
      @exogendesign4582 Před rokem

      @@Aiden-lu3vj what do you mean? you want to create a log in window? you can start small by usung string and saving it to database once you can read it out through your head, add soms flavor to improve security such as hashing and salt, also using encryption such as eramake which is popular with the c# ecosystem. For start search "login form with sql using c#, there's a ton.

  • @t3hPoundcake
    @t3hPoundcake Před rokem

    In the App.xaml startup method I'm getting an unhandled exception with the loginView.Close(); call. I cannot figure out what is going on with it, if you click the custom close button while you're on the login screen the application closes and breaks at that line, saying you cannot change the state of a window while it is closing. I've tried a bunch of different ideas and cannot figure out why it's throwing this error. If I try to simply HIDE the loginView, pressing the close button hides the login view and shows the MainView window regardless of if you are logged in or not.

    • @t3hPoundcake
      @t3hPoundcake Před rokem

      If anyone is having this issue, simply changing loginView.Close() to loginView.Hide() solves the issue - not sure if that is the best way to handle this but it works and the application can still be closed via the custom close button click event anyway, so it seems to work fine.

    • @TheMBasith
      @TheMBasith Před 5 měsíci

      before loginView.Close(); add if (mainView.IsLoaded) { loginView.Close(); }