C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Udpating DataTable and RowState property of a DataRow


Posted Date: 16 Apr 2008    Resource Type: Articles    Category: .NET Framework

Posted By: Moosa Sahib       Member Level: Silver
Rating:     Points: 10



Modifying Data in a Table



The DataRow class provides three methods for suspending, reactivating the state of the row while editing.
They are,

(1)BeginEdit
(2)EndEdit
(3)CancelEdit


Eg.,

Dim dr as DataRow = dt.Rows(2)
dr.BeginEdit()
dr(0)="hi"
dr(1)="22"
dr.EndEdit()


DataRowVersion


It is used when retrieving the value found in a datarow by using Item property.Four types,

(1)Current
(2)Default
(3)Original
(4)Proposed

E.g.,


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dr As DataRow

dr = dtTable.Rows(1)

'Represents the Original value
lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)

'Begin to edit the row
dr.BeginEdit()

dr(0) = "2"
dr(1) = "4444"
dr(2) = "8889"

' Values are changed into 2,4444,8889(Proposed value)
lblProposed.Text = "CTCID is" & dr(0, DataRowVersion.Proposed) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Proposed) & "." & "Amount is " & dr(2, DataRowVersion.Proposed)

'Values are not changed, old original values still exists (Current Value)
lblCurrent1.Text = "CTCID is" & dr(0, DataRowVersion.Current) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Current) & "." & "Amount is " & dr(2, DataRowVersion.Current)

' Values are changed into 2,4444,8889(Default value)
lblDefault.Text = "CTCID is" & dr(0, DataRowVersion.Default) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Default) & "." & "Amount is " & dr(2, DataRowVersion.Default)

'Ending the edition of a row.
dr.EndEdit()

'Values are changed into 2,4444,8889(Current value)
lblCurrent.Text = "CTCID is" & dr(0, DataRowVersion.Current) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Current) & "." & "Amount is " & dr(2, DataRowVersion.Current)

'Values are not changed, old original values still exists (Original Value)
lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)

'Make changes into the datatable
dtTable.AcceptChanges()

'Now Values are changed, old original values not exists (Original Value)
lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _
& "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)


End Sub






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Editing datarow  .  Editing Data Table  .  DataRow State  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Enumeration in C#.NET,VB.NET
Previous Resource: Show all GridView Rows in EditMode
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

Help Desk

Contact Us    Privacy Policy    Terms Of Use