Solved

Find & Edit a row in a datatable

Posted on 2004-08-27
3
176 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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