473,513 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating Datasets

How can I manipulate Datasets, such as getting a specific row based on a key
column value. Of course, I could loop through all the rows in the entire
dataset each time I needed something, but is there an easier way? I want to
be able to execute the equivalent of SQL statements including insert, delete
etc.

Any ideas? Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
Mar 3 '08 #1
5 2008

You have to

1. Perform a .Select
2. Change the data
3. (Sometimes) commit the changes

Let's say you have a strong dataset called EmployeeDS with an
Employee(table). EmpID(int),LastName(string),FirstName(string)
EmployeeDS ds = //populate the ds somehow with employees

DataRow[] rows = ds.Select("EmpID=123");
//vb dim rows as DataRows() = ds.Select("EmpID=123");
//or
//DataRow[]rows = ds.Select("LastName='Smith'");
//or vb
//dim rows as DataRows() = ds.Select("LastName='Smith'");

now you have an array of rows

you loop over them, but you'll have to cast them

dim i as integer
for i = 0 to rows.Length - 1 //or .Count?
EmployeeDS.EmployeeRow currentRow = ctype(rows(i),
EmployeeDS.EmployeeRow
currentRow.LastName = "Jones" //change the data

next i

Console.Writeline (ds.GetXml())

Something like that.

"Anil Gupte" <an*******@icinema.comwrote in message
news:uz****************@TK2MSFTNGP02.phx.gbl...
How can I manipulate Datasets, such as getting a specific row based on a
key column value. Of course, I could loop through all the rows in the
entire dataset each time I needed something, but is there an easier way?
I want to be able to execute the equivalent of SQL statements including
insert, delete etc.

Any ideas? Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com


Mar 3 '08 #2
Anil Gupte wrote:
I thought DataViews were read-only? I am using VB.Net 2003
How so? A DataView is just a another look at rows in a DataTable.

Some ways to modify data in through a DataView:

Dim DV As DataView = New DataView(MyTable)
DV.Item(3).Item("CheckFlag") = 1

Dim drv As DataRowView
drv = DV.Item(3)
drv("CheckFlag") = 1

For Each drv In DV
drv("CheckFlag") = 1
Next drv

Dim nID As Integer = 23
dv.Sort = "EmpID"
drv = dv.FindRows(nID).GetValue(0)
drv("CheckFlag") = 1

' etc...
Mar 4 '08 #3
Steve,
It's a mini-database. :)
It is certainly not or should add to your text, "single user", this has
given very much misunderstandings in past.

One of the disadvantages is than even that you have to read and write
forever the complete XML file while it is not changeble on disk.

Cor
Mar 4 '08 #4
Anil-

A little addition to your two other answers,

http://msdn2.microsoft.com/en-us/library/bb386977.aspx

-Cor

"Anil Gupte" <an*******@icinema.comschreef in bericht
news:uz****************@TK2MSFTNGP02.phx.gbl...
How can I manipulate Datasets, such as getting a specific row based on a
key column value. Of course, I could loop through all the rows in the
entire dataset each time I needed something, but is there an easier way?
I want to be able to execute the equivalent of SQL statements including
insert, delete etc.

Any ideas? Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

Mar 4 '08 #5
From Sams Teach Yourself Visual Basic in 21 Days on page 714:

"Dataviews are much like read-only datasets. Because they're read-only,
they work like snapshots of your data, and they provide you with faster
access to that data than datasets can. The term "data view" means just
that - a view of your data - and they're usually used as containers for a
subset of your data."

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Steve Gerrard" <my********@comcast.netwrote in message
news:Lq******************************@comcast.com. ..
Anil Gupte wrote:
>I thought DataViews were read-only? I am using VB.Net 2003

How so? A DataView is just a another look at rows in a DataTable.

Some ways to modify data in through a DataView:

Dim DV As DataView = New DataView(MyTable)
DV.Item(3).Item("CheckFlag") = 1

Dim drv As DataRowView
drv = DV.Item(3)
drv("CheckFlag") = 1

For Each drv In DV
drv("CheckFlag") = 1
Next drv

Dim nID As Integer = 23
dv.Sort = "EmpID"
drv = dv.FindRows(nID).GetValue(0)
drv("CheckFlag") = 1

' etc...


Mar 4 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1725
by: Alpha | last post by:
I have a small Window application and through out the different forms I create a different dataset. At the begining I used the Tools to drag and drop the SqlDataAdapter, connection and dataset...
3
1139
by: fripper | last post by:
I am at my wits end trying to do a very simple task in VB .Net. I have spent a number of hours trying to figure out how to use datasets, datatables and the Datagrid control but I am lost in the...
9
2880
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
16
1913
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
2
7809
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: ...
3
1226
by: John | last post by:
Hi I have two data adapters bound to two separate tables. How can I; 1. Loop through all records one by one in one of them while reading column values, and 2. Insert a record from data...
0
1203
by: S.Tedeschi | last post by:
Hi all; as posted some days ago, I'm converting an on-line app; I used to heavily rely on strongly-typed DataSets directly dropped onto pages, and so viewed by code(-behind) as well. In the next...
12
3550
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a...
9
1931
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.