Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Data Manipulation with ADO.NET

By Exforsys | on July 15, 2005 |
VB.NET 2005

Editing Data With ADO .NET

In this tutorial you will learn about Editing Data With ADO .NET – Updating Data, Adding Data, Typed data set, Untyped data set, Deleting Data, Editing with a DataGrid.

Updating Data

The SqlDataAdapter’s update method is called whenever the changes made to a DataSet has to be applied to the underlying table. The SqlDataAdapter is instantiated using eh SELECT statement and the compiler generates the statements for UPDATE, INSERT and DELETE. The changes made to the DataSet are then applied to the Database. However considerations for automatic update will fail if there is no primary key assigned to the data in the Database. The update is also likely to fail if the AcceptChanges method of the DataSet is called before the Update method of the SqlDataAdapter is called. The dataset maintains the row versions like Deleted rows, modified rows, inserted row and so on. When the UPDATE method is called this version information is used to update the relevant changes to the database. The AcceptChanges method removes all the versions and hence the UPDATE will fail. AcceptChanges is usually called after Update method.

The Update method of the Adapter will be called within a Try Catch block. When two tables are updated in a dataset, the following sequence is advised as a best practice:

(a) Update Child table – Delete records. The code sample is given below

(b) Dim DeletedChildRecords as DataTable = _

(c) DSet.Table.GetChanges(DataRowState.Deleted) DataAdapter.Update(DeletedChildRecords)

(d) Parent Table – Insert, Update, and delete records

(e) Child Table – Insert and update records.

Adding Data

Adding new rows to the DataSet can be performed in any one of the following methods:

Typed data set

Dim newCustomersRow as DataSetClass.Customers.CustomersRow

newCustomersRow = DataSetInstance.Customers.NewCustomersRow()

newCustomersRow.CustomerID = "ALFKI"

newCustomersRow.CompanyName = "Alfreds Futterkiste"

DataSetInstance.Customers.Rows.Add(newCustomersRow)

Untyped data set

Dim newCustomersRow As DataRow = DataSet1.Tables("Customers").NewRow()

newCustomersRow("CustomerID") = "ALFKI"

newCustomersRow("CompanyName") = "Alfreds Futterkiste"

DataSet1.Tables("Customers").Rows.Add(newCustomersRow)

Deleting Data

In order to retain the information that the dataset needs to send updates to the data source, the System.Data.DataRow.Delete method is used to remove rows in a data table. For example, if the application uses a TableAdapter (or DataAdapter), the adapter’s Update method will delete rows in the database that have a RowState of DataRowState.Deleted.

If the application does not need to send updates back to a data source, then it is possible to remove records by directly accessing the data row collection DataRowCollection.Remove

To delete records from a data table call the DataRow.Delete method of a DataRow. This method does not physically remove the record; instead, it marks the record for deletion.

If the count property of a DataRowCollection is obtained, the resulting count includes records that have been marked for deletion. To get an accurate count of only records that are not marked for deletion, the user can loop through the collection looking at the RowState property of each record (records marked for deletion have a RowState of DataRowState.Deleted).

The following line of code is used to delete nth row.

DataSetXX.TableYYY.Rows(n).Delete()

Editing with a DataGrid

A DataGrid can be edited using the BeginEdit and EndEdit methods of the DataGrid. The following illustration clarifies the concepts of editing a DataGrid.

1. Identify the current cell by its ColumnNumber and RowNumber properties and call the method BeginEdit of the DataGrid .
2. Create the DataTable and DataRow Objects.
3. Assign the edited values to the DataRow.
4. Accept changes by calling the AcceptChanges method of DataRow.
5. Call the EndEdit method of the DataGrid.

Click here to view sample code

« « Finding and Sorting Data in DataSets
Web Services – SOAP, WSDL, Disco and UDDI » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • The .NET Framework Architecture Part 1

    May 27, 2005 - 0 Comment
  • Microsoft .NET Creating Installation Components

    August 10, 2005 - 0 Comment
  • Event Handling In Visual Basic .NET

    June 11, 2005 - 0 Comment
  • SQL Server Ad Hoc Queries

    July 9, 2005 - 0 Comment
  • VB.NET Validation Controls

    July 4, 2005 - 0 Comment
  • The .NET Framework Architecture Part 2

    May 30, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Building Graphical Interface elements

    June 11, 2005 - 0 Comment
  • SQL Server Stored Procedures

    July 11, 2005 - 0 Comment
  • Web Application Testing in VB.NET 2005

    July 28, 2005 - 0 Comment
  • Microsoft .NET Creating Installation Components

    August 10, 2005 - 0 Comment
  • Shared Assembly

    August 9, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Tracing VB.NET Windows Application

    August 9, 2005 - 0 Comment
  • VB.NET Windows Application Testing

    August 9, 2005 - 0 Comment
  • The Registry Editor in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Customizing Setup Project in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Deploying Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Debugging Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Working with Legacy Code and COM Components

    July 30, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Microsoft .NET Creating Installation Components
  • Shared Assembly
  • The File Types Editor
  • Tracing VB.NET Windows Application
  • VB.NET Windows Application Testing

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT