Locating a specific row

EStallworth

Well-known member
Joined
Aug 14, 2006
Messages
75
Location
Destin, FL
Programming Experience
Beginner
I have an application that receives partial payments (on an account) in order for the user to post a payment on that account within a database. It only receives account information from those who have not fully balanced their account. What I am having trouble with is deleting that row, of account information, from the table in which it is being pulled once a full payment has been made.

The way I have it set up now is for the app to load the whole table into a
dataset, find the specified row based on the primary key and remove it based on the same info, accept the changes and finally update the underlying DB. The problem is that it is not working and I believe that "remove" is dependent upon a certain position. Is there any other way to locate a certain row within a DB?¿ Thanks in advance for any help provided.

VB.NET:
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2]SqlDataAdapter3.Fill(DataSet111)[/SIZE]
 
[SIZE=2]DataSet111.PreReceivePayments.Rows.Find(ComboBox1.SelectedValue) [/SIZE]
 
[SIZE=2]DataSet111.PreReceivePayments.Rows.Remove(ComboBox1.SelectedValue) [/SIZE]
 
[SIZE=2]DataSet111.AcceptChanges() [/SIZE]
 
[SIZE=2]SqlDataAdapter3.Update(DataSet111)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2]MessageBox.Show(ex.Message)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try [/COLOR][/SIZE]
 
The find function returns the found datarow. So if you code like this....


VB.NET:
Dim Dr as datarow = DataSet111.PreReceivePayments.Rows.Find(ComboBox1.SelectedValue)
 
'Then we want to delete the row, not remove it. We do this by setting it's row state to deleted...
 
Dr.Delete
You also do not want to be calling accept changes as this will set all the row states back to default. After the update method of the dataadapter has been called acceptchanges is implicitly called.
 
You also do not want to be calling accept changes as this will set all the row states back to default.
Just to qualify a tiny point on this, incase you (or other readers) missed it, If you call AcceptChanges() before you send a datatable into an Update() call, there will be nothing to update because all the changed rows will be confirmed as accepted values and marked unchanged by the call to AcceptChanges()
 
Back
Top