How to implement delete with DataView?

S

Siegfried Heintze

I have a datagrid bound to a dataview which is connected to a dataset which
is bound to MSAccess.

The following code deletes a record, but not the one for which I click the
delete link. I think this is because the data rows are in a different order
because of the data view. I think I have to translate the row number I'm
receiving. How do I do this?

Incidently, is there an easier way to delete a record? I was hoping there
was a simple function I could call in the dataset instead of having to
populate the parameters of a stored procedure or prepared statement.
Thanks,
Siegfried

Private Sub dgAssertions_DeleteCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles dgAssertions.DeleteCommand
Dim index As Integer
index = e.Item.ItemIndex
rebind()
' Add code to delete data from data source.
Dim dr As dsAssertions.AssertionsRow =
DsAssertions1.Assertions.Rows(index)
'DsAssertions1.Assertions.Rows.RemoveAt(index)
daAssertions.DeleteCommand.Parameters(0).Value = dr.nAssertion
daAssertions.DeleteCommand.Parameters(1).Value = dr.ridCase
daAssertions.DeleteCommand.Parameters(2).Value = dr.A
daAssertions.DeleteCommand.Parameters(3).Value = dr.A
daAssertions.DeleteCommand.Parameters(4).Value = dr.B
daAssertions.DeleteCommand.Parameters(5).Value = dr.B
daAssertions.DeleteCommand.Parameters(6).Value = dr.C
daAssertions.DeleteCommand.Parameters(7).Value = dr.C
daAssertions.DeleteCommand.Parameters(8).Value = dr.D
daAssertions.DeleteCommand.Parameters(9).Value = dr.D
daAssertions.DeleteCommand.Parameters(10).Value = dr.E
daAssertions.DeleteCommand.Parameters(11).Value = dr.E
daAssertions.DeleteCommand.Connection.Open()
daAssertions.DeleteCommand.ExecuteScalar()
rebind()
End Sub
 
Y

Yan-Hong Huang[MSFT]

Hello Siegfried,

Please refer to http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskworkingwithrecordsindataview.asp?frame=true for
how to work with records in dataview.

Hope it helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Siegfried Heintze" <[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
!Subject: How to implement delete with DataView?
!Lines: 43
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
!Message-ID: <4xURa.90683$Ph3.11041@sccrnsc04>
!NNTP-Posting-Host: 12.203.244.128
!X-Complaints-To: (e-mail address removed)
!X-Trace: sccrnsc04 1058542784 12.203.244.128 (Fri, 18 Jul 2003 15:39:44 GMT)
!NNTP-Posting-Date: Fri, 18 Jul 2003 15:39:44 GMT
!Organization: Comcast Online
!Date: Fri, 18 Jul 2003 15:39:44 GMT
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!newsfeed.icl.net!
newsfeed.fjserv.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!zen.net.uk!in.100proofnews.com!in.100proofnews.com!
elnk-atl-nf1!newsfeed.earthlink.net!prodigy.com!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!
sccrnsc04.POSTED!not-for-mail
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.datagridcontrol:5748
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
!
!I have a datagrid bound to a dataview which is connected to a dataset which
!is bound to MSAccess.
!
!The following code deletes a record, but not the one for which I click the
!delete link. I think this is because the data rows are in a different order
!because of the data view. I think I have to translate the row number I'm
!receiving. How do I do this?
!
!Incidently, is there an easier way to delete a record? I was hoping there
!was a simple function I could call in the dataset instead of having to
!populate the parameters of a stored procedure or prepared statement.
!Thanks,
! Siegfried
!
! Private Sub dgAssertions_DeleteCommand(ByVal source As Object, _
! ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
! Handles dgAssertions.DeleteCommand
! Dim index As Integer
! index = e.Item.ItemIndex
! rebind()
! ' Add code to delete data from data source.
! Dim dr As dsAssertions.AssertionsRow =
!DsAssertions1.Assertions.Rows(index)
! 'DsAssertions1.Assertions.Rows.RemoveAt(index)
! daAssertions.DeleteCommand.Parameters(0).Value = dr.nAssertion
! daAssertions.DeleteCommand.Parameters(1).Value = dr.ridCase
! daAssertions.DeleteCommand.Parameters(2).Value = dr.A
! daAssertions.DeleteCommand.Parameters(3).Value = dr.A
! daAssertions.DeleteCommand.Parameters(4).Value = dr.B
! daAssertions.DeleteCommand.Parameters(5).Value = dr.B
! daAssertions.DeleteCommand.Parameters(6).Value = dr.C
! daAssertions.DeleteCommand.Parameters(7).Value = dr.C
! daAssertions.DeleteCommand.Parameters(8).Value = dr.D
! daAssertions.DeleteCommand.Parameters(9).Value = dr.D
! daAssertions.DeleteCommand.Parameters(10).Value = dr.E
! daAssertions.DeleteCommand.Parameters(11).Value = dr.E
! daAssertions.DeleteCommand.Connection.Open()
! daAssertions.DeleteCommand.ExecuteScalar()
! rebind()
! End Sub
!
!
!
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top