How to Auto-refresh Data on a DataGridView in C# winforms - TKH

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ • 34

  • @abelii8726
    @abelii8726 Рік тому

    I spent 2 days trying to solve a threading issue, and failed. This solution worked wonderfully, thank you!!

    • @tkh15
      @tkh15  Рік тому +1

      I'm glad to be of help... ❤️

  • @sonmai2326
    @sonmai2326 2 роки тому +2

    HELPFUL VIDEO. THANK YOU SO SO MUCH FOR HELPING ME

  • @PATELARYA-tm9si
    @PATELARYA-tm9si Рік тому

    By using your code i solve my auto refreshing data in datagridview 👍👍

  • @PHARMACAFEchannel
    @PHARMACAFEchannel Рік тому +2

    Is it ok to query db every 5 seconds where lot of transactions are happening.

    • @tkh15
      @tkh15  Рік тому

      Yes very possible my friend... you can use a timer to place an interval on the dB transactions... if you want, I could do a video on that...

  • @yissou3176
    @yissou3176 2 роки тому +2

    hey i have to do that in c++ but it's a bit hard to translate, can you explain what the "[0]" does a in DS.Table pls ?
    also can we do it with several table ?

    • @tkh15
      @tkh15  2 роки тому

      Hi, sorry I'm unfamiliar with c++ ... However, the name of my table is 'Register'. So, DS.Table[0] refers to an array element '0' which is 'Register'.

  • @NeeteshAgarwal-qi3oz
    @NeeteshAgarwal-qi3oz Рік тому +1

    Hello I have one Exe and same instance I have opened in another system and there is common database(MS_SQL) connected through intranet. I want to know If i have done a operation in one form I want that same thing update in another exe without manual click

    • @tkh15
      @tkh15  Рік тому

      Hello Neetesh, Do you mean you have the same application (software) running on 2 different computers, and they both connect to the same MS SQL server. And you would like the data to update/display on both systems in real time when there's a change in data without having to refresh it manually on any of the systems... Am I right?

    • @NeeteshAgarwal-qi3oz
      @NeeteshAgarwal-qi3oz Рік тому

      @@tkh15 Yes You got it right .

    • @tkh15
      @tkh15  Рік тому

      Yes, this method works well too... However, if you want me to do a video on how this can be achieved practically, I can do it...

  • @unbelieverr
    @unbelieverr Рік тому +1

    i've got one little problem with your method, every time a timer ticks it returns the selected row to the first one. any solution to this problem? cause it gets really annoying when i try to scroll around my datagridview and try to delete a row i've selected

    • @tkh15
      @tkh15  Рік тому

      There should be a way around it... I think when inputting the refresh code, you could try to alter the datagridview settings programmatically; not to scroll to top/bottom... though I'm not quite sure the exact way to do this... hope it helps

    • @unbelieverr
      @unbelieverr Рік тому +1

      @@tkh15 solved it by adding ur refresh code metod at the end of the "add" and "remove" button click events! thanks anyway

  • @omarrahim673
    @omarrahim673 Рік тому

    Our respected professor, I made Form 1 and Form 2, and put a button to move from Form 1 to 2, so what is the code that we write to update Form 2? Thank you.

    • @tkh15
      @tkh15  Рік тому +1

      On the button click in form 1, try this:
      Form2 fn = new Form2();
      This.hide();
      fn.show();
      ✌️

  • @mateuzin632
    @mateuzin632 2 роки тому +1

    You're the best man

  • @armuc6941
    @armuc6941 Рік тому +1

    i dont undrestnd, if y restart yr application, is the datas will be refresh ?

    • @tkh15
      @tkh15  Рік тому

      Pls take note that if the data was stored into the database before you close your application, when you restart the application, your data will surely be displayed again... 😉

    • @armuc6941
      @armuc6941 Рік тому +1

      @@tkh15 thanks, d you have a video like dataBase ?

    • @tkh15
      @tkh15  Рік тому

      Would you like me to do a video to practically show you how it works?

    • @armuc6941
      @armuc6941 Рік тому

      @@tkh15 let me so to tell you what exactly i need.
      i create a c# database, i seccessful export/import of dataGritView in Excel file. the probleme, when this application closed i can't to restore automaticly the data in dataGritView !! is obligatory to import excel file again. each time i open application the dataGritView is umpty.

  • @raduluchian7008
    @raduluchian7008 9 місяців тому

    System.ArgumentException: 'Keyword not supported: 'provider'.'

    • @tkh15
      @tkh15  9 місяців тому

      What did you do to make this error show up?

    • @raduluchian7008
      @raduluchian7008 9 місяців тому

      @@tkh15 String con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/apl_vs/ActeAditionale2022/acteAditionale/acteAditionale/actAd.accdb";
      ...
      public void ImprospateazaGrila()
      {
      string sqlstm = "select * from baza";
      SqlDataAdapter SDA = new SqlDataAdapter(sqlstm, con);
      DataSet DS = new System.Data.DataSet();
      SDA.Fill(DS, "baza");
      dgvAngajati.DataSource = DS.Tables[0];
      }

    • @raduluchian7008
      @raduluchian7008 9 місяців тому +1

      @@tkh15 OK. I managed to replace it
      SqlDataAdapter SDA = new SqlDataAdapter(sqlstm, con);
      with OleDbDataAdapter SDA = new OleDbDataAdapter (sqlstm, con);
      thk !

    • @tkh15
      @tkh15  9 місяців тому

      Awesome! 👍

    • @tkh15
      @tkh15  9 місяців тому +1

      You can start by using try and catch stmts to be able to see error codes... it makes you understand better why an error was generated...
      try
      {
      //Codes
      }
      catch(Exception ex)
      {
      Message box.Show(ex.Message);
      }
      Although, you already fixed it... it's also good to place this... before writing dB codes cos the outcome are quite uncertain sometimes... for example if you have an integer field and a user enters alphabets... with try and catch, the program won't close without letting you/the user know why there was an error... to better be able to fix or manage it... 🥂

  • @shariful5030
    @shariful5030 Рік тому +1

    yeah.

  • @Gadreel.
    @Gadreel. Рік тому

    Is there OLEDB?

  • @lazyturtle61
    @lazyturtle61 2 роки тому +2

    subscribed