PC Review


Reply
Thread Tools Rate Thread

Delete rows from DataGrid not working?

 
 
=?Utf-8?B?Sm9iIExvdA==?=
Guest
Posts: n/a
 
      30th Jul 2004
My DataGrid is bound to a DataSet and showing only those records whose Client_Liability_ID IS NULL and I am using RowFilter to do so. Following is the code:

'Set Select Command for WithdrawalDA.
WithdrawalDA.SelectCommand = New SqlCommand
With WithdrawalDA.SelectCommand
.Connection = myConn
.CommandType = CommandType.StoredProcedure
.CommandText = "spSelectWithdrawals"
.Parameters.Clear()
.Parameters.Add("@Plan_ID", Me.PlanID)
End With

'Fill DataSet.
WithdrawalDA.FillSchema(myDataSet, SchemaType.Mapped, "Withdrawals")
WithdrawalDA.Fill(myDataSet, "Withdrawals")

'Set Insert Command for WithdrawalDA.
WithdrawalDA.InsertCommand = New SqlCommand
With WithdrawalDA.InsertCommand
.Connection = myConn
.CommandType = CommandType.StoredProcedure
.CommandText = "spInsertWithdrawals"
.Parameters.Clear()
.Parameters.Add("@Plan_ID", SqlDbType.Int, 4, "Plan_ID")
.Parameters.Add("@Client_Liability_ID", SqlDbType.Int, 4, "Client_Liability_ID")
.Parameters.Add("@WithdrawalDate", SqlDbType.DateTime, 8, "WithdrawalDate")
.Parameters.Add("@Amount", SqlDbType.Money, 8, "Amount")
.Parameters.Add("@Reason", SqlDbType.VarChar, 60, "Reason")
End With

'Set Update Command for WithdrawalDA.
WithdrawalDA.UpdateCommand = New SqlCommand
With WithdrawalDA.UpdateCommand
.Connection = myConn
.CommandType = CommandType.StoredProcedure
.CommandText = "spUpdateWithdrawals"
.Parameters.Clear()
.Parameters.Add("@Withdrawal_ID", SqlDbType.Int, 4, "Withdrawal_ID")
.Parameters.Add("@WithdrawalDate", SqlDbType.DateTime, 8, "WithdrawalDate")
.Parameters.Add("@Amount", SqlDbType.Money, 8, "Amount")
.Parameters.Add("@Reason", SqlDbType.VarChar, 60, "Reason")
End With

'Set Delete Command for WithdrawalDA.
WithdrawalDA.DeleteCommand = New SqlCommand
With WithdrawalDA.DeleteCommand
.Connection = myConn
.CommandType = CommandType.StoredProcedure
.CommandText = "spDeleteWithdrawals"
.Parameters.Clear()
.Parameters.Add("@Withdrawal_ID", SqlDbType.Int, 4, "Withdrawal_ID")
End With

grdWithdrawals.TableStyles.Clear()
grdWithdrawals.DataSource = myDataSet.Tables("Withdrawals").DefaultView
myDataSet.Tables("Withdrawals").DefaultView.RowFilter = "Client_Liability_ID IS NULL"

Now my problem is how I can delete records which are not shown in the DataGrid. Let’s say if I want to delete records where Client_Liability_ID = 1

I wrote the following procedure, but it doesn’t seem to work as it does not delete records from the Database.

Private Sub RemoveUnconsolidatedDebts(ByVal clientLiabilityID As Integer)

For Each dr As DataRow In myDataSet.Tables("Withdrawals").Select("Client_Liability_ID = " & clientLiabilityID)
myDataSet.Tables("Withdrawals").Rows.Remove(dr)
Next

End Sub

What am I doing wrong here?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows From DataGrid rn5a@rediffmail.com Microsoft ASP .NET 0 4th Dec 2006 07:18 AM
delete rows from datagrid Sam Microsoft VB .NET 10 4th Apr 2005 10:51 AM
How to Delete rows from a sorted DataGrid =?Utf-8?B?REJX?= Microsoft C# .NET 0 12th Nov 2004 07:13 PM
Delete mutiple rows in a dataGrid using delete Key =?Utf-8?B?TVZC?= Microsoft Dot NET Framework 0 26th Oct 2004 04:39 AM
delete selected rows from a datagrid =?Utf-8?B?RGljaw==?= Microsoft Dot NET Framework Forms 4 30th Sep 2004 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 PM.