Solved

Find & Edit a row in a datatable

Posted on 2004-08-27
3
179 Views
Last Modified: 2010-04-23
I am trying to find and edit a row in a datatable.

I set up a new datarow dr.

dr = catalogues.CatalogueTypes.Rows.Find(oldCatalogueIDCode)

Great this gets me the datarow to edit, then i

dr.BeginEdit()
dr(catalogues.CatalogueTypes.CatalogueIDColumn.ColumnName) = newCatalogueIDCode

This gives the new datarow dr a new catalogueid in the catalogueidcolumn

I then try and accept the changes

dr.AcceptChanges()
catalogues.CatalogueTypes.AcceptChanges()

BUT the dataset doesn't get updated or changed just the datarow dr.
If i specify directly the datarow eg.

dr = catalogues.CatalogueTypes.Rows(2)

This works no problems.

So, how do i find a row given a value and then edit it in the datatable and acceptchanges.

Thank you for any help.

Zac
0
Comment
Question by:zaceverett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 125 total points
ID: 11912018
All I have right now is a datagrid sample:

you need to have a primary key in the datagrid

dim ds as dataset
dim sTableName as string = "MYTABLE"
dim myDataAdapter As OleDb.OleDbDataAdapter
 
'dg is my datagrid
     '*****************
        'BEGIN EDIT CODE go get primary key
        Dim pk(0) As DataColumn
        pk(0) = ds.Tables(sTableName).Columns("MYID")   '<--- the name of your primary key
        ds.Tables(sTableName).PrimaryKey = pk

        '********* Use this for single edit mode **************
        CurRow = ds.Tables(sTableName).Rows.Find(dg.Item(dg.CurrentRowIndex, 0))
        CurRow.BeginEdit()
        CurRow("OnHand") = dg.Item(dg.CurrentRowIndex, 2)
        CurRow("Description") = dg.Item(dg.CurrentRowIndex, 1)
        CurRow.EndEdit()
        'MsgBox("Record edited successfully")
        CurRow.AcceptChanges()
        myDataAdapter.Update(ds.Tables(sTableName))
        'END EDIT CODE  

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question