?
Solved

Find & Edit a row in a datatable

Posted on 2004-08-27
3
Medium Priority
?
187 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
1 Comment
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

809 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