Solved

Reading and updating records using ado.net

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

Expert Comment

by:DotNetLover_Baan
ID: 11984514
0
 
LVL 3

Expert Comment

by:Scoobyed
ID: 11988164
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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