Results 1 to 2 of 2

Thread: Update data in DataTable

  1. #1

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Update data in DataTable

    How to make the data in the DataTable automatically change when there is the Insert, Update or Delete.

    my code like this:
    VB.NET Code:
    1. Imports System.Data
    2. Imports System.Data.OleDb
    3.  
    4. Public Class frmSupplier
    5.  
    6.     Dim dt As New DataTable
    7.  
    8.  
    9.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    10.         Me.WindowState = FormWindowState.Maximized
    11.     End Sub
    12.  
    13.     Sub setData()
    14.         Try
    15.  
    16.             Dim sql As String = "select vendor_id,vendor_name,address,phone from inv_t_vendors order by vendor_id"
    17.             dt = ggDB.SelectRecordToDT(dbConn, sql)
    18.  
    19.             dg.DataSource = dt
    20.  
    21.         Catch ex As Exception
    22.             ERRDesc(ex)
    23.         End Try
    24.  
    25.  
    26.     End Sub
    27.  
    28.     Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
    29.         setData()
    30.     End Sub
    31.  
    32.     Private Sub tFilter_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tFilter.TextChanged
    33.         ' filter data
    34.     End Sub
    35.  
    36.  
    37.     Function AddData()
    38.         'load form entry
    39.         ' refresh data
    40.     End Function
    41.  
    42.     Sub ModifyData()
    43.         'load form entry
    44.         ' refresh data
    45.     End Sub
    46.  
    47.     Sub DELETEData()
    48.         ' delete data
    49.         ' refresh data
    50.     End Sub
    51. End Class

    I want the data in a DataTable is changed according to the data on the actual database.

    whether I should call my method setData() at AddData, ModifyData & DeleteData for getting the data at this time.


    thank you

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Update data in DataTable

    If you're talking about your DataTable being updated when you update the database then you shouldn;t have to. You're supposed to update the DataTable first and then save the changes from there to the database, not the other way around.

    If you're talking about your DataTable being updated when some other client updates the database then, generally speaking you can't. If you want data from the database then you have to ask for it. It's not going to send it to you uninvited.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width