Solved

Reading and updating records using ado.net

Posted on 2004-09-05
7
244 Views
Last Modified: 2010-04-23
I need some code sample on using the ado dataset to read and update records. I am looking for sample in which we can use syntax as in vb6 recordset such as recordset.fields("column1")="test" to update data. (not the code where we have to use update SQL statement.)
0
Comment
Question by:swtirs
[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
7 Comments
 
LVL 1

Assisted Solution

by:con_iezekiel
con_iezekiel earned 150 total points
ID: 11984299
hi

   In order to connect and manipulate a database with ADO.NET you need 4 objects
   1. The connection object
   2. The command object
   3. The data adapter
   4. The Data set

So
dim conn as oledbconnection = new oledbconnection(connectionstring)
dim comm as oledbcommand= new oledbcommand(sqlstring,conn)

dim da as oledbdataadapter= new oledbdataadapter(comm)
dim ds as data.dataset

da.fill(Ds,"tablename")

now you have you data according to sqlstring into the dataset called ds
in order to update the dataset with the database
da.update(ds,"tablename")

i think this will be helpfull
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:swtirs
ID: 11988915
hi con_iezekiel

Thanks for the posting. In the ds (dataset), for instance if I opened a tabled named "Employee" and I want to change the field "Age",
1) how will I change it.
2) After changing how could I update the changes.
3) When I opened dataset how could I check if it returned any value
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 350 total points
ID: 11990140
Hi again,

1) You have to know the column structure and the row number that you need. then, you can change the specific cell you want...    DataSet.Tables("Employee").Columns(3).Item(5)="New Age"    You can find the row you want by using some "If" condition and checking for the desired value in any column.

2) da.update(ds,"tablename")   will do the update for you.

3) Check for the data count;  
                           If DataSet.Tables("Employee").Rows.Count > 0 Then
                                       'Data is returned
                           Else
                                       'No data found
                           End If
-Baan
0
 

Author Comment

by:swtirs
ID: 11991715
Hi

Using if condition to locate the data after opening the entire table is very tedious, bcos in case when table has huge amount of data. How could we easily extract the row we want and then extract column data required. I would appreciate if anybody can post a sample that read the table "Employee" for one particular employee no "1122", then modify his age then save.
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11993503
Hi there,
then change you SQL query to ...   SELECT * FROM Employee WHERE EmployeeNo=1122
Fill the dataset using adapter. Modify it and update it.
-Baan
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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