Delete a row in a datagrid and the underlying database vb net 2003

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 3
Reputation: destino is an unknown quantity at this point 
Solved Threads: 0
destino destino is offline Offline
Newbie Poster

Delete a row in a datagrid and the underlying database vb net 2003

 
0
  #1
Aug 30th, 2008
Greetings.

I've hunted around quite a bit on this one. There seem to be as many potential solutions as there are folks who have asked the question. I'm rewriting a vb6 app in .net and rather than use the conversion process i felt that the app could do with a complete redesign

I have an access database being displayed by a datagrid in vb.net 2003. Works fine I can search and sort and edit and add but i can't delete.


  1.  
  2. Dim mySurname As String
  3. mySurname = txt_SearchSurname.Text & "%"
  4. OleDbDataAdapter1.SelectCommand.Parameters("SURNAME").Value = mySurname
  5.  
  6. DataSet21.Clear()
  7. OleDbDataAdapter1.Fill(DataSet21)
.

I can update rows in the datagrid and update the database with
  1. OleDbDataAdapter1.Update(DataSet21)

I can add new rows and get them added in the database but as for deleting i'm stuck.

I would appreciate help to get a simple way to add delete functionality.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 3
Reputation: destino is an unknown quantity at this point 
Solved Threads: 0
destino destino is offline Offline
Newbie Poster

Re: Delete a row in a datagrid and the underlying database vb net 2003

 
0
  #2
Aug 30th, 2008
Greetings.

I have managed to get it working. I'm indebted to arjunsasidharan who posted some help to another member.

Not sure if it is the "correct" way or if there is a better way but it seems to work.

Is there a better way of refreshing the datagrid after the row has been deleted in the underlying database.

I've just cleared the datagrid and reloaded it

  1.  
  2. DBConn = New OleDb.OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
  3. "ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Program Files\Skimail" & _
  4. "\NZSKIMAIL.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transact" & _
  5. "ions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:S" & _
  6. "FP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Passwo" & _
  7. "rd=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compac" & _
  8. "t=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:E" & _
  9. "ncrypt Database=False")
  10. ln_CurrentTrakID = DataGrid1.Item(ln_CurrentRowNumber, 43)
  11.  
  12. DBDelete.CommandText = "Delete From NZDATA Where TRAKIDreal = " & Trim(Str(ln_CurrentTrakID))
  13. DBDelete.Connection = DBConn
  14. DBDelete.Connection.Open()
  15. DBDelete.ExecuteNonQuery()
  16. DBConn.Close()
  17.  
  18. DataSet21.Clear()
  19. OleDbDataAdapter1.Fill(DataSet21)
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 23
Reputation: asnider is an unknown quantity at this point 
Solved Threads: 2
asnider asnider is offline Offline
Newbie Poster

Re: Delete a row in a datagrid and the underlying database vb net 2003

 
0
  #3
Aug 30th, 2008
Cool, thanks for following up with that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum


Views: 1722 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC