473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Delete rows from DataGrid not working?

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.RowFil ter = "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_Lia bility_ID = " & clientLiabilityID)
myDataSet.Tables("Withdrawals").Rows.Remove(dr)
Next

End Sub

What am I doing wrong here?
Nov 22 '05 #1
0 881

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Job Lot | last post by:
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....
0
by: Mark Jones | last post by:
I'm trying to delete a row from a DataGrid using a ButtonColumn with CommandName="Delete" by deleting the row in the underlying DataTable datasource, but it doesn't seem to be working at the...
2
by: Mark Jones | last post by:
I'm trying to delete data from a DataGrid using a ButtonColumn with a CommandName="Delete" but it's not working a the min. I'm using session data which fills a DataTable which then fills the...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
2
by: Jim McGivney | last post by:
I am using a Microsoft Book as a guide and trying to construct a Delete Command Event Handler for a DataGrid. The book lists the statement: ...
2
by: Ryan Liu | last post by:
private void dt_RowDeleted(object sender, DataRowChangeEventArgs e) { int id= (int)e.Row; if(id >5) { e.Row.RejectChanges(); MessageBox.Show(this, "Can not delete!" + id); }
5
by: rn5a | last post by:
The .NET 2.0 documentation states the following: When using a DataSet or DataTable in conjunction with a DataAdapter & a relational data source, use the Delete method of the DataRow to remove...
0
by: rn5a | last post by:
All the rows in a DataGrid are accompanied by a CheckBox. When a user checks the rows & clicks a Button, the checked rows get deleted. For e.g. assume that the DataGrid displays 10 rows. A user...
10
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.