Solved

Reading and updating records using ado.net

Posted on 2004-09-05
7
203 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
Comment Utility
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
Comment Utility
0
 
LVL 3

Expert Comment

by:Scoobyed
Comment Utility
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:swtirs
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now