Results 1 to 8 of 8

Thread: Cast DataTable to get its Update method?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Cast DataTable to get its Update method?

    I came across an article (with code) that described how to extend a BindingSource component to add some useful features.

    https://www.codeguru.com/dotnet/exte...rce-component/

    The code includes the following:

    Code:
    Private Sub _PositionChanged(ByVal sender As Object, ByVal e As EventArgs) _
        Handles Me.PositionChanged
        If IsCurrentDirty Then
            If AutoSave Or MessageBox.Show(_msg, "Confirm Save",
                    MessageBoxButtons.YesNo) = DialogResult.Yes Then
                Try
                    'cast table as ITableUpdate to get the Update method
                    CType(_dataTable, Biz._Interface.ITableUpdate).Update()
                Catch ex As Exception
                    Win.Logger.LogError(_form, ex, _dataTable.TableName & " Update")
                End Try
            Else
                Me.CancelEdit()
                _dataTable.RejectChanges()
            End If
            IsCurrentDirty = False
        End If
    End Sub
    The highlighted statement shows "Type 'Biz._Interface.ITableUpdate' is not defined." in the VS Error List.

    The article was written in 2008 and the author isn't available to answer this question.

    How can I fix this problem? Any advice will be much appreciated!
    Last edited by Mark@SF; Aug 11th, 2022 at 04:09 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Cast DataTable to get its Update method?

    Why not just…

    _dataTable.UpDate

    ???

    I’ve never seen anything similar to your code before…

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Cast DataTable to get its Update method?

    What is Biz? I've never heard of that. Perhaps somebody else has, but if not, then it sounds like the code you have is based on some third party library that you don't have...and based on what you said, it sounds like it may no longer exist.
    My usual boring signature: Nothing

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Cast DataTable to get its Update method?

    Quote Originally Posted by .paul. View Post
    Why not just…

    _dataTable.UpDate

    ???

    I’ve never seen anything similar to your code before…
    Actually… I apologise, it’d be a DataAdaptor you’d update…

    https://docs.microsoft.com/en-us/dot...h-dataadapters

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: Cast DataTable to get its Update method?

    paul and shaggy -

    I know my question is a weird one because it's about code that I didn't write. But, the example that is in the referenced link is very interesting. It was published on the CodeGuru website (so I'm assuming it was a bonafide working example).

    The gist of the article was to extend the BindingSource component to do several useful things, including auto-saving a "dirty" DataRow. In order to do that, the author appears to have figured out how to "map" the DataAdapter.Update method in a generic way (i.e., without explicitly declaring it in the extended BindingSource.

    The line that causes the error involves the ITableUpdate interface. What is that? I couldn't find anything about it via Google.

    I am hoping that somebody reading this thread might know how to do this...
    Last edited by Mark@SF; Aug 11th, 2022 at 08:00 PM.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: Cast DataTable to get its Update method?

    The author of the CodeGuru article was David Catherman and per the below link, his extended BindingSource article was part of a four-part project.

    https://www.codeguru.com/visual-basi...s-on-tutorial/

    Unfortunately, I can't find the other parts of the project.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Cast DataTable to get its Update method?

    On the face of it, DataAdapter.Update isn't all that special. You can call GetChanges on the Datatable to returns the set of rows that have changes, but even that isn't all that special. The Status of each Datarow will be Unchanged, Added, Modified, or Deleted. You can iterate through the rows in the datatable and call either INSERT (added), UPDATE (modified), or DELETE (deleted) on each row, as appropriate. The difficulty isn't so much the Update method, it's getting an appropriate SQL Statement for each of those different queries.
    My usual boring signature: Nothing

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Cast DataTable to get its Update method?

    Much, if not all, of that looks like a bad idea, including the part that you're trying to use. A DataTable is supposed to be for data storage. Building the retrieval and/or saving of data into that is a crime against the Single Responsibility Principle. It's getting back to the VB6 way of doing things where the Recordset did everything. .NET tends to use multiple smaller types for specific purposes, rather than one big type that does every job.

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