Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing an MS access record , getting the current row.

Status
Not open for further replies.

Mootser13

Programmer
Sep 7, 2005
30
0
0
US
Maybe it's just me, but this seems correct.
I have a dataset pointing to an MS Access db, I can fill the dataset and seea ll of the information in there. But When I go to update the DB, I want to update the row selected in my combobox.

Here's the code I have:

Public Function GetRow() As DataRow
On Error Resume Next
Dim bm As BindingManagerBase
Dim drv As DataRowView
bm = Me.BindingContext(DataSet, "table")

drv = CType(bm.Current, DataRowView)
GetRow = drv.Row
MsgBox(drv.Row.ToString)
Return GetRow


End Function

Then I call the function when I need the row number:
Dim drCurrent As DataRow
drCurrent = GetRow()
drCurrent.Item("Column1") = TextBox2.Text
drCurrent.Item("Column2") = TextBox1.Text
Me.BindingContext(DataSet, "table").EndCurrentEdit()
Me.TableAdapter.Update(DataSet)

Yet the row that get's updated it not the row I have selected.
Anyone know of a better way to do this ?
Mootser13


 
Is your message box (drv.Row.ToString) showing the value you expected?
 
No it just shows the .NET namespace being accessed.
 
Could you show the code where you are binding the dataset to the form and to the controls?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
I am just using VB.NET 2005. Binding is in the properties of the Adapter, dataset, So forth...

My form does show the data from the table fileds to textboxes...

I guess I need to get the row that I want to modify.
 
rjoubert (Programmer) 28 Jul 06 10:29

Try dv.Row(1)

This returns the first columns' value. And not the row itself.
 
I meant for you to put that in your Msgbox call.

Msgbox(drv.Row(1))
 
rjoubert

yeah, I tried that try catch block and it returned an error since in the catch block I cannot return an empty Row().

I actually got this to work, the code above is actually working, but the database isn't getting updated in the project, it is actually getting update in the bin folder where the Vstudio goes and does it's build.

If I do a build I can goto the release folder, run the exe and it works great.

Now I am trying to get the delete row working:
Here is my code for that.

Public Function GetRow() As DataRow
On Error Resume Next
Dim bm As BindingManagerBase
Dim drv As DataRowView
bm = Me.BindingContext(DataSet, "table")

drv = CType(bm.Current, DataRowView)
GetRow = drv.Row
'MsgBox(drv.Row(0))
Return drv.Row


End Function

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim drCurrent As DataRow
drCurrent = GetRow()
drCurrent.Delete()
Me.BindingContext(DataSet, "table").EndCurrentEdit()
Me.BlindsTableAdapter.Update(DataSet)
Me.BlindsTableAdapter.Fill(Me.DataSet.table)
End Sub

This ends up deleting the first and always the first record of the database.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top