Solved

Reading and updating records using ado.net

Posted on 2004-09-05
7
214 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
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, f…

863 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

25 Experts available now in Live!

Get 1:1 Help Now