|
-
Jul 22nd, 2004, 10:47 PM
#1
Thread Starter
Lively Member
-
Jul 23rd, 2004, 12:00 AM
#2
Is that all you have for the update?
Post the code that goes before and after that, to give us a better view.
-
Jul 23rd, 2004, 12:33 AM
#3
Thread Starter
Lively Member
well, for my delete button my code is:
VB Code:
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Try
BindingContext(ds, "QuoteDoc").RemoveAt(BindingContext(ds, "QuoteDoc").Position)
BindingContext(ds, "QuoteTran").RemoveAt(BindingContext(ds, "QuoteTran").Position)
daDoc.Update(ds)
daTran.Update(ds)
Catch ex As Exception
End Try
End Sub
-
Jul 23rd, 2004, 12:56 AM
#4
Sorry, I really don't know what BindingContext is. (Can you explain?)
Try this:
VB Code:
Dim cbuild As SqlClient.SqlCommandBuilder
cbuild = New SqlClient.SqlCommandBuilder(daDoc)
daDoc.DeleteCommand = cbuild.GetDeleteCommand()
daDoc.Update(ds, "Products")
ds.AcceptChanges()
daDoc.DeleteCommand.Connection.Close()
Then repeat for daTrans.
-
Jul 23rd, 2004, 01:23 AM
#5
Thread Starter
Lively Member
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!
-
Jul 23rd, 2004, 01:45 AM
#6
Thread Starter
Lively Member
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:
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Dim cbuild As System.Data.OleDb.OleDbCommandBuilder
Try
cbuild = New System.Data.OleDb.OleDbCommandBuilder(daDoc)
daDoc.DeleteCommand = cbuild.GetDeleteCommand
daDoc.Update(ds, "QuoteDoc")
ds.AcceptChanges()
daDoc.DeleteCommand.Connection.Close()
cbuild = New System.Data.OleDb.OleDbCommandBuilder(daTran)
daTran.DeleteCommand = cbuild.GetDeleteCommand
daTran.Update(ds, "Quotetran")
ds.AcceptChanges()
daTran.DeleteCommand.Connection.Close()
MsgBox("Record deleted.", MsgBoxStyle.OKOnly, "Update")
Catch ex As Exception
End Try
End Sub
-
Jul 23rd, 2004, 02:01 AM
#7
Remove one of the ds.AcceptChanges lines, and try putting the remaining ds.AcceptChanges at the end of the sub.
-
Jul 25th, 2004, 06:55 PM
#8
Thread Starter
Lively Member
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:
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Dim cbuild As System.Data.OleDb.OleDbCommandBuilder
Try
BindingContext(ds, "QuoteDoc").RemoveAt(BindingContext(ds, "QuoteDoc").Position)
cbuild = New System.Data.OleDb.OleDbCommandBuilder(daDoc)
daDoc.DeleteCommand = cbuild.GetDeleteCommand
daDoc.Update(ds, "QuoteDoc")
BindingContext(ds, "QuoteTran").RemoveAt(BindingContext(ds, "QuoteTran").Position)
cbuild = New System.Data.OleDb.OleDbCommandBuilder(daTran)
daTran.DeleteCommand = cbuild.GetDeleteCommand
daTran.Update(ds, "Quotetran")
ds.AcceptChanges()
daTran.DeleteCommand.Connection.Close()
MsgBox("Record deleted.", MsgBoxStyle.OKOnly, "Update")
Catch ex As Exception
End Try
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|