Solved

Find & Edit a row in a datatable

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now