?
Solved

Find & Edit a row in a datatable

Posted on 2004-08-27
3
Medium Priority
?
181 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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