Solved

Reading and updating records using ado.net

Posted on 2004-09-05
7
226 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
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11984514
0
 
LVL 3

Expert Comment

by:Scoobyed
ID: 11988164
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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