473,809 Members | 2,575 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 2020

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),Last Name(string),Fi rstName(string)
EmployeeDS ds = //populate the ds somehow with employees

DataRow[] rows = ds.Select("EmpI D=123");
//vb dim rows as DataRows() = ds.Select("EmpI D=123");
//or
//DataRow[]rows = ds.Select("Last Name='Smith'");
//or vb
//dim rows as DataRows() = ds.Select("Last Name='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.Empl oyeeRow currentRow = ctype(rows(i),
EmployeeDS.Empl oyeeRow
currentRow.Last Name = "Jones" //change the data

next i

Console.Writeli ne (ds.GetXml())

Something like that.

"Anil Gupte" <an*******@icin ema.comwrote in message
news:uz******** ********@TK2MSF TNGP02.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(MyTabl e)
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 misunderstandin gs 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*******@icin ema.comschreef in bericht
news:uz******** ********@TK2MSF TNGP02.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********@com cast.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(MyTabl e)
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
1738
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 objects to the frist few forms but then later I removed those and created these objects in my code. I now see 3 datasets in the Solution Explorer panel part but not all the datasets that I have in my codes. Are these 3 datasets leftover from the...
3
1152
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 mass of functionality and details that these entail. My task is simple ... I simply want to display a bunch of data (not from an SQL darabase) in tabular form ... I want to be able to set the width of each column and the foreground/background...
9
2918
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 answered... There are articles on the new TableAdapters where it says that a key new advantage is that a single TableAdapter, which can have multiple queries, can be used on multiple forms. Now that was in an article on using TableAdapters with...
16
1939
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
2
7823
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: DataSet ds = new DataSet(); ds.ReadXml(@"\usr\tmp\sample.xml"); dataGridView.DataSource = ds; dataGridView.DataMember = "targetElement"; What I found through experimentation is that the DataMember may specify
3
1237
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 adapter A into data adapter B via code?
0
1223
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 two weeks I discovered that such objects are no more directly usable in pages, namely in DataGrid which don't see them any more. Even if rebuilt in Component Designer, and so visible in code, DataSets are invisible in Page Designer, so now it's...
12
3606
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 gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
9
1945
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
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.