Results 1 to 8 of 8

Thread: one quick question...(NO ANWER YET)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125

    Exclamation one quick question...(NO ANWER YET)

    I'm not really sure if my logic is right so I need your opinion on this...

    I have a form with textboxes and a datagrid. What i want to do is to edit and delete the displayed record...by the way, the texboxes are bound to a table and the datagrid is bound to another table, I already have my relationship...so, is it right that I have two update statements? one for the master table and one for the detail table? if so, why won't it work?

    Hope someone could correct me on this....thanks a lot people!

    this is my code for updating:

    daDoc.Update(ds) 'for the master table
    daTran.Update(ds) 'for the detail table

    Please also suggest a better code for updating! thanks a bunch!
    Last edited by siomai; Aug 17th, 2004 at 03:02 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Is that all you have for the update?

    Post the code that goes before and after that, to give us a better view.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    well, for my delete button my code is:


    VB Code:
    1. Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
    2.         Try
    3.             BindingContext(ds, "QuoteDoc").RemoveAt(BindingContext(ds, "QuoteDoc").Position)
    4.             BindingContext(ds, "QuoteTran").RemoveAt(BindingContext(ds, "QuoteTran").Position)
    5.             daDoc.Update(ds)
    6.             daTran.Update(ds)
    7.  
    8.         Catch ex As Exception
    9.         End Try
    10.     End Sub

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Sorry, I really don't know what BindingContext is. (Can you explain?)

    Try this:

    VB Code:
    1. Dim cbuild As SqlClient.SqlCommandBuilder
    2. cbuild = New SqlClient.SqlCommandBuilder(daDoc)
    3.             daDoc.DeleteCommand = cbuild.GetDeleteCommand()
    4.             daDoc.Update(ds, "Products")
    5.             ds.AcceptChanges()
    6.             daDoc.DeleteCommand.Connection.Close()

    Then repeat for daTrans.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    i just found this code from microsoft visual basic .net step by step book. It defined bindingcontext as an object that keeps track of all the CurrencyManager objects on my form...

    I'll try your code and let you know what happens...thanks!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    hi!

    I tried using ur code but it didn't delete the record in my database and did not display any error when I run it...

    this is my code now...could you tell me what's wrong with it?

    VB Code:
    1. Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
    2.             Dim cbuild As System.Data.OleDb.OleDbCommandBuilder
    3.             Try
    4.             cbuild = New System.Data.OleDb.OleDbCommandBuilder(daDoc)
    5.             daDoc.DeleteCommand = cbuild.GetDeleteCommand
    6.             daDoc.Update(ds, "QuoteDoc")
    7.             ds.AcceptChanges()
    8.             daDoc.DeleteCommand.Connection.Close()
    9.  
    10.             cbuild = New System.Data.OleDb.OleDbCommandBuilder(daTran)
    11.             daTran.DeleteCommand = cbuild.GetDeleteCommand
    12.             daTran.Update(ds, "Quotetran")
    13.             ds.AcceptChanges()
    14.             daTran.DeleteCommand.Connection.Close()
    15.             MsgBox("Record deleted.", MsgBoxStyle.OKOnly, "Update")
    16.         Catch ex As Exception
    17.         End Try
    18.     End Sub

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Remove one of the ds.AcceptChanges lines, and try putting the remaining ds.AcceptChanges at the end of the sub.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    I followed your instructions and your code but it still did not delete the record in my dataset and in my tables. What I did is I attached the bindingcontext line and it deleted the record in my dataset and table. The problem now is, it only deletes the record in my master table (QuoteDoc). The details of the record are still in my details table (QuoteTran). What should I do? What's wrong with the codes?

    VB Code:
    1. Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
    2.     Dim cbuild As System.Data.OleDb.OleDbCommandBuilder
    3.         Try
    4.  
    5.             BindingContext(ds, "QuoteDoc").RemoveAt(BindingContext(ds, "QuoteDoc").Position)
    6.             cbuild = New System.Data.OleDb.OleDbCommandBuilder(daDoc)
    7.             daDoc.DeleteCommand = cbuild.GetDeleteCommand
    8.             daDoc.Update(ds, "QuoteDoc")
    9.                 BindingContext(ds, "QuoteTran").RemoveAt(BindingContext(ds, "QuoteTran").Position)
    10.                 cbuild = New System.Data.OleDb.OleDbCommandBuilder(daTran)
    11.                 daTran.DeleteCommand = cbuild.GetDeleteCommand
    12.                 daTran.Update(ds, "Quotetran")
    13.                 ds.AcceptChanges()
    14.                 daTran.DeleteCommand.Connection.Close()
    15.  
    16.             MsgBox("Record deleted.", MsgBoxStyle.OKOnly, "Update")
    17.         Catch ex As Exception
    18.         End Try
    19.     End Sub

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