my program deletes the first record in my database...[RESOLVED]
hi!
I've been posting here questions and I'm glad to have found the answers from all of you. I think you're all good and very helpful to beginners like me...
Well, I just want to ask for some help...I have a form with a master/detail relationship...what I want to do is to update and delete records. I have started coding my delete button. Thought it was working well but I noticed just this mornng that it deletes the first record even if I navigated to the record that I wanted to delete. Please try to help me! I need to finish this soon...I hope someone will assist me on this!
Thanks in advance!
Last edited by siomai; Aug 19th, 2004 at 03:07 AM.
If you can remember, you helped me on this and told you it's working already but to my surprise, it deletes the first record of my database.
This only happens upon loading then I go straight to my Find button then navigate through my First,Next,Previous and Last buttons but if from saving a new record it works fine.
I hope I did not confuse you.
If it's not too much to ask and if you're just interested, please take a look at my program that I attached here. I'm very much willing to accept suggestions and recommendations from all of you!
I'm really new with programming so my logic still sucks...could you somehow tell me how to instruct my program to delete the current/selected record? I have a master/detail relationship and what I do is I fill the form (textboxes for my master and a datagrid for my details) then navigate to the record I want to delete.
For i = 0 to ds.Tables("QuoteTran").Rows.Count - 1
If grid.IsSelected(i) = True Then
'Found the selected row
dsTables("QuoteTran").Rows(i).Delete
Exit For
End If
Next
I am not sure how well this will work for datagrids who have their order sorted and swapped around. Some of the others may of had more experience with datagrids.
then I'll just repeat the code for the details table? or it will automatically delete the details in my grid? I have a master/detail form with textboxes for the master and a datagrid for the details.
ExpertSearch is a program I downloaded from the internet.Kindly add the reference ExpertSearch to make my program work...please bear with my code. I know it's really ugly and long...i'm no programmer til now...
that's why i'm always posting here hoping someone could help me. Anyway, i attached the dll file of ExpertSearch and can be found in the bin folder of my program. Thanks for taking time in looking at my program andy! I'll wait for your suggestions. I'll really appreciate it!
Mabuhay brown monkey! Thanks for replying to my post...i'm kind of giving up on this program already! I'm not really a good programmer (yet! hehe) but could you explain to me what your code does?(if you don't mind) I mean I know it deletes records but how?
i'm a cebuano so "mabuhi ka siomai". hehehe. my program deletes every row clicked on a grid. say i click on the third row and press the delete button, it deletes the third row on a table buffered and on the database as well.
I see...but could you help me in deleting my record with master/detail relationship? this is the code I have and it deletes the first record in my database only. Please please help me with this one! I'll be forever grateful!
Code:
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
I have already created the relation in my find button click event...hope you could help me. Thanks in advance kababayan!
i got my problem....now how to point my program to select the current record...
I read about bindingcontext and it is by default, pointing to the first record (0 in index) that's why my program deletes the first record.
Now what I want to know now is how I could point my program to select the current record displayed in my form and point that record to my database so I can delete it. (help me code this please)
Hope the vb.net gurus out there would help me. Many thanks!
Hi!
I'm not just deleting the record in my datagrid. I want to delete the current record displayed in my form. I understand that when you have a relation set, it automatically deletes the details or the child records of that current mother record. This works fine with me, it deletes my mother and child records but the problem is it doesn't delete the currently displayed record. Instead, it deletes the first record in my database.
What does this line point to...(i mean what record in my database?)
Correct me if I'm wrong but I think this is pointing to the currently displayed record!!! I've been trying to solve this glitch for a week now but to no luck, the glitch still exists....please help me.
To anyone who has done program with a master/detail form, please share your knowledge to me. I'll be very very thankful if I'd be able to solve this problem.Thanks in advance.
please help me! I know you have other stuff to do but a simple suggestion could make a difference. I really don't know where to go from here. Please please help me!
hi! thanks for replying to my long thread...
I'm no expert in programming. Actually this is my first program ever (well i did the calculator thingy...). Anyway, could you show me how? I just want to be able to delete a master/detail (parent/child) record. What my current program does is it deletes the first record in my database though i displayed another record in my form. It seems that my code now doesn't point to the record that i actually want to delete.
never tried your code though and i don't do binding. and i'm a newbie. i tried purchase requisition (pr) thing. the master detail relation but i don't do the relation object. here's what i do, to sql server 2000, design table. say the pr master. click the relationships. then new relation. mostly the pr master number relates the pr details number. there should be something like a checkbox underneath with text "Cascade Delete Related Records". check this mate. this might help you. if you want an example i'll try to have an example but quiet busy now. perhaps i can post sample tomorrow. the pr...
Last edited by brown monkey; Aug 19th, 2004 at 01:24 AM.
what you could try, which i often do to debug errors i get like this, is simply display the position thats selected befopre your delete command. i havent really ever used datasets, but try somehting like this:
Code:
Dim cbuild As System.Data.OleDb.OleDbCommandBuilder
Try
' check position of current bindingcontext
msgbox(BindingContext(ds,"QuoteDoc").Position)
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
see what im doing there? that way you can identify whats causing your problem, by checking different values and making sure they are set correctly.
my problem is solved! I've found a link and tried the code it showed. I used parameters to make my program select the record/s it has to delete...and it worked!
But without you guys...I would've given up programming!
There's more to come from me..haha! this program isn't done yet! Please watch out for my queries. Again thanks a lot!
VB forums.com people are the best!