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

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ธ.ค. 2024

ความคิดเห็น • 94

  • @Your_Better_You
    @Your_Better_You 2 ปีที่แล้ว +9

    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;

  • @kunleth
    @kunleth ปีที่แล้ว +8

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

  • @entemolu1
    @entemolu1 2 ปีที่แล้ว +4

    Learn from an expert. Wonderful tutorials for professional also

  • @ilianabenchikh9330
    @ilianabenchikh9330 ปีที่แล้ว +1

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

    • @StrawHatGyro
      @StrawHatGyro ปีที่แล้ว +1

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

    • @DirePantsDim
      @DirePantsDim ปีที่แล้ว

      Good luck! :)

  • @ghelonicomaligaya3232
    @ghelonicomaligaya3232 2 ปีที่แล้ว +1

    Finally! Thank you for this.

  • @hasanmougharbel8030
    @hasanmougharbel8030 2 ปีที่แล้ว +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.

  • @MrJuche23
    @MrJuche23 2 ปีที่แล้ว +1

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

  • @minoubrc4773
    @minoubrc4773 ปีที่แล้ว

    Really well explained

  • @nnerD-e6x
    @nnerD-e6x ปีที่แล้ว

    thank you for the great video!

  • @son1powa
    @son1powa ปีที่แล้ว +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 ?

  • @sirinebibicha2024
    @sirinebibicha2024 ปีที่แล้ว

    Great video .. Thank you👌

  • @WillChorm
    @WillChorm 22 วันที่ผ่านมา

    你的数据库在哪里?怎么做的访问啊,没有看到你的项目里面有数据库呢?

  • @robertorinaldi977
    @robertorinaldi977 ปีที่แล้ว +3

    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?

    • @j00semane
      @j00semane 5 วันที่ผ่านมา

      i tried like 20 different methods of getting rid of the error, and only one worked. i am by no means an expert, so if anyone else has a cleaner solution let me know.
      anyway, if you are running a newer version of .NET than the creator of the video, there are a few things that need to be coded differently. first, you will need to explicitly unsubscribe to the event handler. in this video he uses a lambda expression for event subscription but does not explicitly manage them which could result in memory leaks. this is not tolerated in newer versions of .NET. The solution is to define the event handler as a variable so it can be unsubscribed properly.
      second, the order that events are processed in WPF causes more issues. shutdown will execute, but while it is executing, the isvisiblechanged event subscription will trigger. loginView is effectively closed, but the event subscription to isvisiblechanged still runs and tries to close loginView again, resulting in an exception.
      the only way i was able to fix this issue was to declare a public boolean value that is set when the exit button is closed. below is the code that works.
      //this method is in the LoginView.xaml.cs file for the close button event
      private void btnClose_Click(object sender, RoutedEventArgs e)
      {
      //set appshutdown flag to true when close button is clicked and pass to App : Applicaiton class
      var app = (App)Application.Current;
      app.isAppShuttingDown = true;
      //initiate shutdown
      Application.Current.Shutdown();
      }
      //this is the class for app.xaml.cs
      public partial class App : Application
      {
      //create command to get/set flag
      public bool isAppShuttingDown { get; set; }
      protected void ApplicationStart(object sender, StartupEventArgs e)
      {
      var loginView = new LoginView();
      loginView.Show();
      //declare handler as variable so we can explicitly unsubscribe
      DependencyPropertyChangedEventHandler handler = null;
      handler = (s, ev) =>
      {
      //check to see if app is shutting down BEFORE we check the state of the loginView window
      if (!isAppShuttingDown)
      {
      if (loginView.IsVisible == false && loginView.IsLoaded)
      {
      loginView.IsVisibleChanged -= handler; // Unsubscribe properly
      var mainView = new MainView();
      mainView.Show();
      loginView.Close();
      }
      }
      };
      loginView.IsVisibleChanged += handler;
      }
      }
      hope this helps!

  • @janslanina2209
    @janslanina2209 2 ปีที่แล้ว

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

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@RJCodeAdvanceEN what about the animation , storyboard

    • @janslanina2209
      @janslanina2209 2 ปีที่แล้ว

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

  • @iamhuihui
    @iamhuihui 11 หลายเดือนก่อน

    "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?"

  • @doannam5900
    @doannam5900 2 ปีที่แล้ว

    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 ปีที่แล้ว

      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 ปีที่แล้ว

      @@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

  • @bennzzen86
    @bennzzen86 2 ปีที่แล้ว

    Thank You, Adblocker

  • @t3hPoundcake
    @t3hPoundcake ปีที่แล้ว +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?

    • @NEOOOOOOON
      @NEOOOOOOON 5 หลายเดือนก่อน

      you can add:
      if (Thread.CurrentPrincipal == null)
      {
      return;
      }
      just before it sets the variable

  • @inhnguyen-zq6tq
    @inhnguyen-zq6tq 2 ปีที่แล้ว +1

    Magic !

  • @RajeevRanjan-z9l
    @RajeevRanjan-z9l 2 หลายเดือนก่อน

    hello, I need help. I have done everything in this video. I think my Login button is some how not working how it was supposed to be work. but when I tried through Click event It started working. Why is that and how to correct that. Thanks for your Time.

  • @wsilvawgt
    @wsilvawgt 8 หลายเดือนก่อน

    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

  • @ЯшаОрлов-м7р
    @ЯшаОрлов-м7р ปีที่แล้ว

    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?

  • @wsilvawgt
    @wsilvawgt 8 หลายเดือนก่อน

    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.

  • @mplaimer
    @mplaimer 2 ปีที่แล้ว

    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 2 ปีที่แล้ว

      do u know where u can make an username and password

    • @wamique
      @wamique ปีที่แล้ว

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

    • @mplaimer
      @mplaimer ปีที่แล้ว

      @@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"

  • @Elta305
    @Elta305 ปีที่แล้ว

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

  • @tesladude2822
    @tesladude2822 ปีที่แล้ว +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 ปีที่แล้ว

      its happend to me too you have the solution?

    • @tesladude2822
      @tesladude2822 ปีที่แล้ว

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

  • @daliangilbert
    @daliangilbert 2 ปีที่แล้ว +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 ปีที่แล้ว

      have you found a solution to the problem?

    • @Den-Irenicus
      @Den-Irenicus ปีที่แล้ว

      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 ปีที่แล้ว

      @@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 ปีที่แล้ว

      @@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 :)

    • @j00semane
      @j00semane วันที่ผ่านมา +1

      @@BreezElly check out my other comment, it explains the issue and my method of solving it. Unfortunately you dont want to use visibility.hidden. that may prevent the error, but you can potentially still have the login window running in the background on a separate thread. you still need to make sure the window is properly closed and disposed of.

  • @vinnypassmore5657
    @vinnypassmore5657 2 หลายเดือนก่อน

    Hows the implicit symbol done?

  • @ZacharyRodney
    @ZacharyRodney 2 ปีที่แล้ว

    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 2 ปีที่แล้ว

      do u know where u can make an username and password

  • @josaphatkayombo9057
    @josaphatkayombo9057 2 ปีที่แล้ว

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

  • @edence6001
    @edence6001 ปีที่แล้ว +5

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

    • @StrawHatGyro
      @StrawHatGyro ปีที่แล้ว

      Спасибо, мой друг!

  • @deakattila
    @deakattila ปีที่แล้ว

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

  • @jatinkamble7720
    @jatinkamble7720 ปีที่แล้ว

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

  • @SirLuke33
    @SirLuke33 ปีที่แล้ว

    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 ปีที่แล้ว

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

  • @xibble4320
    @xibble4320 2 ปีที่แล้ว +1

    How do I make and use the database?

    • @carapysca1238
      @carapysca1238 2 ปีที่แล้ว

      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

  • @miyano2544
    @miyano2544 2 ปีที่แล้ว

    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  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว

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

  • @tuannguyenvanquoc2670
    @tuannguyenvanquoc2670 2 ปีที่แล้ว

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

    • @j00semane
      @j00semane วันที่ผ่านมา

      do you have a local database setup already? if not, you'll need to create one on your machine to connect to it. when creating the database, make sure mixed authentication is enabled so you dont have to use integrated security.

  • @subi-333
    @subi-333 ปีที่แล้ว

    Thank u

  • @kopch1k82
    @kopch1k82 2 ปีที่แล้ว

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

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  2 ปีที่แล้ว

      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 2 ปีที่แล้ว

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

  • @kylechesshir7681
    @kylechesshir7681 5 หลายเดือนก่อน

    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.

  • @GalaxyTJ
    @GalaxyTJ 2 ปีที่แล้ว

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

    • @Den-Irenicus
      @Den-Irenicus ปีที่แล้ว +2

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

    • @jedit2586
      @jedit2586 ปีที่แล้ว +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 ปีที่แล้ว +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

  • @Dysonator
    @Dysonator 6 หลายเดือนก่อน

    This code is not checked in to github.

  • @thaithanhloc6791
    @thaithanhloc6791 2 ปีที่แล้ว

    can you make more videos with mongodb

  • @Fayritail1337
    @Fayritail1337 2 ปีที่แล้ว +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 2 ปีที่แล้ว

      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 2 ปีที่แล้ว

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

    • @Aiden-lu3vj
      @Aiden-lu3vj 2 ปีที่แล้ว

      do u know where u can make an username and password

    • @exogendesign4582
      @exogendesign4582 2 ปีที่แล้ว

      @@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.

  • @TrollpoeCarter-y7k
    @TrollpoeCarter-y7k 3 หลายเดือนก่อน

    McKenzie Points

  • @KimbraPrecissi-f5p
    @KimbraPrecissi-f5p 3 หลายเดือนก่อน

    Albert Isle

  • @SandraYoung-j5b
    @SandraYoung-j5b 3 หลายเดือนก่อน

    Williams Gary Harris Helen Young Robert

  • @t3hPoundcake
    @t3hPoundcake ปีที่แล้ว

    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 ปีที่แล้ว

      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 10 หลายเดือนก่อน

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

  • @HeadingWatch
    @HeadingWatch 3 หลายเดือนก่อน

    Jackson Christopher Hall Scott Davis Margaret