Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. How to refresh Database Connections

How to refresh Database Connections

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasehelptutorialquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akosidandan
    wrote on last edited by
    #1

    Hello, I would like to ask how can I show what I have recently updated in my database I just use textboxe's to show my data but my problem is that I does not show it yet until I restart my program.Not like my delete command that it immediately affect what changes I have made in the database. Problem Conclusion: How to immediately show changes made after updating the database For more details below here are my codes: My Declarations:

    Dim con As New OleDb.OleDbConnection
    Dim da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim dt As New DataTable
    Dim sSQL As String
    Dim maxRows As Integer
    Dim inc As Integer

    My sub to display my database records to textbox:

    Private Sub setRecords()
    Try
    'set the specific records
    txtProduct_ID.Text = dt.Rows(inc).Item("productID")
    txtProductName.Text = dt.Rows(inc).Item("productName")
    txtProductDescription.Text = dt.Rows(inc).Item("productDescription")
    txtProductCategory.Text = dt.Rows(inc).Item("productCategory")
    txtProductStatus.Text = dt.Rows(inc).Item("productStatus")
    txtProductPrice.Text = dt.Rows(inc).Item("productPrice")
    txtProductQuantity.Text = dt.Rows(inc).Item("productQuantity")
    datePicker.Text = dt.Rows(inc).Item("productDateAdded")
    'disable editing when form in load
    txtProduct_ID.Enabled = False
    txtProductName.Enabled = False
    txtProductDescription.Enabled = False
    txtProductCategory.Enabled = False
    txtProductStatus.Enabled = False
    txtProductPrice.Enabled = False
    txtProductQuantity.Enabled = False
    datePicker.Enabled = False
    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try
    End Sub

    MY code in update:

    con.Close()

        Try
            con.Open()
            Try
                'add a new row 
                Dim Rows As DataRow
                Rows = dt.NewRow
                Rows.Item("productID") = Val(txtProduct\_ID.Text)
                Rows.Item("productName") = txtProductName.Text
                Rows.Item("productCategory") = txtProductCategory.Text
                Rows.Item("productDescription") = txtProductDescription.Text
                Rows.Item("productStatus") = txtProductStatus.Text
                Rows.Item("productPrice") = Val(txtProductPrice.Text)
                Rows.Item("productQuantit
    
    C 1 Reply Last reply
    0
    • A akosidandan

      Hello, I would like to ask how can I show what I have recently updated in my database I just use textboxe's to show my data but my problem is that I does not show it yet until I restart my program.Not like my delete command that it immediately affect what changes I have made in the database. Problem Conclusion: How to immediately show changes made after updating the database For more details below here are my codes: My Declarations:

      Dim con As New OleDb.OleDbConnection
      Dim da As New OleDb.OleDbDataAdapter
      Dim ds As New DataSet
      Dim dt As New DataTable
      Dim sSQL As String
      Dim maxRows As Integer
      Dim inc As Integer

      My sub to display my database records to textbox:

      Private Sub setRecords()
      Try
      'set the specific records
      txtProduct_ID.Text = dt.Rows(inc).Item("productID")
      txtProductName.Text = dt.Rows(inc).Item("productName")
      txtProductDescription.Text = dt.Rows(inc).Item("productDescription")
      txtProductCategory.Text = dt.Rows(inc).Item("productCategory")
      txtProductStatus.Text = dt.Rows(inc).Item("productStatus")
      txtProductPrice.Text = dt.Rows(inc).Item("productPrice")
      txtProductQuantity.Text = dt.Rows(inc).Item("productQuantity")
      datePicker.Text = dt.Rows(inc).Item("productDateAdded")
      'disable editing when form in load
      txtProduct_ID.Enabled = False
      txtProductName.Enabled = False
      txtProductDescription.Enabled = False
      txtProductCategory.Enabled = False
      txtProductStatus.Enabled = False
      txtProductPrice.Enabled = False
      txtProductQuantity.Enabled = False
      datePicker.Enabled = False
      Catch ex As Exception
      MsgBox(ex.ToString)
      End Try
      End Sub

      MY code in update:

      con.Close()

          Try
              con.Open()
              Try
                  'add a new row 
                  Dim Rows As DataRow
                  Rows = dt.NewRow
                  Rows.Item("productID") = Val(txtProduct\_ID.Text)
                  Rows.Item("productName") = txtProductName.Text
                  Rows.Item("productCategory") = txtProductCategory.Text
                  Rows.Item("productDescription") = txtProductDescription.Text
                  Rows.Item("productStatus") = txtProductStatus.Text
                  Rows.Item("productPrice") = Val(txtProductPrice.Text)
                  Rows.Item("productQuantit
      
      C Offline
      C Offline
      Ciumac Sergiu
      wrote on last edited by
      #2

      All in all, you have Delete, Insert, Update in a class, so you can declare an Event (Modified), and subscribe to it. When it fires, call setRecords sub. In C# it looks as follows:

      public event EventHandler DatabaseDataModified;

      protected virtual void OnDatabaseDataModified(EventArgs args)
      {
      if(DatabaseDataModified != null)
      DatabaseDataModified.Invoke(this, args);
      }

      Call OnDatabaseDataModified method everytime a record is updated in the database. Subscribe to DatabaseDataModified event and call setRecords sub, once the event handler fires. For a more detailed review check publish/subscribe model.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups