473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Need to loop through dataset

CMW
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I
need to search each record in the dataset to see if any data is missing from
the records (i.e., missing first name, missing last name, missing city,
missing state, missing zip, etc.). If I find that a column data is missing
from a record (i.e., last name), I'd like to update a column/field with a
code indicating data is missing (i.e., ErrorCode = 100). Later, another VB
app will only display records with the ErrorCode column set to 100 to allow
a user to correct the missing data.

Can anyone give me some sample code that shows how I might loop through each
record in the dataset to check for any missing column data?

Thank you.
CMW

Nov 20 '05 #1
4 22057
CMW,
David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
provides a number of examples on using DataSets & DataTables, plus a
complete reference for ADO.NET.

How is the first app going to get the DataSet to the second app?

Is ErrorCode on SQL Server (tblformdata) or is it just part of the DataSet?

I would create a DataAdapter to retrieve the data into the DataSet.

I would use a for each loop to check each row of the DataTable. Updating the
ErrorCode column as needed.

Within the other vb app, I would bind to a DataView with a filter criteria
selecting 'bad' records.

Hope this helps
Jay
"CMW" <co*************@hotmail.com> wrote in message
news:lfDlb.2242$e01.3206@attbi_s02...
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I
need to search each record in the dataset to see if any data is missing from the records (i.e., missing first name, missing last name, missing city,
missing state, missing zip, etc.). If I find that a column data is missing
from a record (i.e., last name), I'd like to update a column/field with a
code indicating data is missing (i.e., ErrorCode = 100). Later, another VB
app will only display records with the ErrorCode column set to 100 to allow a user to correct the missing data.

Can anyone give me some sample code that shows how I might loop through each record in the dataset to check for any missing column data?

Thank you.
CMW

Nov 20 '05 #2
CMW,
Based on your email, I should offer a word of caution.

Remember with a DataSet, you are going to download the entire table into the
data set.

You can use a for each to check each row, when you update a row it will be
marked internally as such. You can add rows to the other table, they will
also be flagged as such.

At the end of the process you can use a couple DataAdapters to then update
the SQL Server with the modified data.

I would recommend you check out Sceppa's book.

As I really see you have three options here:
1. Create a SQL Stored Procedure with a cursor & do every thing in SQL
Server, you could even schedule this SP to run periodically, or at the end
of the initialize import.

2. Use a DataSet to process the data, which is what I outlined in my
original response.

3. Use only a DataCommand to create a DataReader to read one record at a
time, if any changes are needed use a second DataCommand to update that row.
A third DataCommand could be used to insert records into your second table.

Sceppa's book should help you decide between 2 & 3. From a performance point
of view 3 will probably be faster, however 2 may be more straight forward to
program. The advantage of 2 is you can save the DataSet as an XML file,
which the second VB app would load and make any changes as the second app
made changes it would then update the SQL Server, the first program would
not update the SQL Server in this case... In fact the original input could
simple put the data in a DataSet...

Hope this helps
Jay

"CMW" <co*************@hotmail.com> wrote in message
news:lfDlb.2242$e01.3206@attbi_s02...
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I
need to search each record in the dataset to see if any data is missing from the records (i.e., missing first name, missing last name, missing city,
missing state, missing zip, etc.). If I find that a column data is missing
from a record (i.e., last name), I'd like to update a column/field with a
code indicating data is missing (i.e., ErrorCode = 100). Later, another VB
app will only display records with the ErrorCode column set to 100 to allow a user to correct the missing data.

Can anyone give me some sample code that shows how I might loop through each record in the dataset to check for any missing column data?

Thank you.
CMW

Nov 20 '05 #3
Hi CMW,

Here's some pretty simple code that loops through a dataset/datatable and
does some update work (oconn is the connection that has already been
established):
Dim dapubcb As New SqlDataAdapter("select * from pubcb where paidstat <>
'Y'", oconn)

Dim dspubcb As New DataSet("pubcb")

Dim commandbuilder_dspubcb As SqlCommandBuilder = New
SqlCommandBuilder(dapubcb)

' you must have either a commandbuilder or update commands to make changes
to the backend (SQL Server)

dapubcb.Fill(dspubcb, "pubcb")

Dim totcbcount As Double

Dim irow as Datarow

For Each irow In dspubcb.Tables(0).Rows

totcbcount += irow("cbamount")

irow("paidstat") = "Y"

irow("vflag") = "Z"

Next

Try

dapubcb.Update(dspubcb, "pubcb")

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

HTH,

Bernie Yaeger
"CMW" <co*************@hotmail.com> wrote in message
news:lfDlb.2242$e01.3206@attbi_s02...
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I
need to search each record in the dataset to see if any data is missing from the records (i.e., missing first name, missing last name, missing city,
missing state, missing zip, etc.). If I find that a column data is missing
from a record (i.e., last name), I'd like to update a column/field with a
code indicating data is missing (i.e., ErrorCode = 100). Later, another VB
app will only display records with the ErrorCode column set to 100 to allow a user to correct the missing data.

Can anyone give me some sample code that shows how I might loop through each record in the dataset to check for any missing column data?

Thank you.
CMW

Nov 20 '05 #4
Cor
Hi CMW,

A dataset has tables, they work in the same way as every other table

So rought written
\\\\
dim i as integer
for i from 1 to dsCMW.tables(0).rows.count - 1
if dsCMW.tables(0).rows(i)("lastname") = dbnull.value then
dsCMW.tables(0).rows(i)("erroritem") = "100"
end if
next
///

I said rough written so if there is an error, don't blaim me?

Cor

Nov 20 '05 #5

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
0
by: Christopher Ambler | last post by:
This is long, but it's driving me nuts. I need some adult supervision :-) (and I'm not above bribing for help) I have a stored procedure that I call that returns XML to me. The SP returns 3...
4
by: edpdc | last post by:
VB .NET I would like to know how to loop through each row in a data set and get a value from a colum in the data set. My data set has multiple columns. I know I have to use the datarow class but...
1
by: Shapper | last post by:
Hello, I have this loop: For Each row As DataRow In dsContent("pagename").Tables(0).Rows Dim div As HtmlGenericControl = CType(Page.FindControl(row("tag_name").ToString), HtmlGenericControl)...
1
by: Jay Zweedyk | last post by:
Ok I want to filter a dataset into a dataview and be able to reference back to the dataset from the filtered dataview. Example: 100 record dataset filter it to a 5 record dataview loop...
6
by: BB | last post by:
Hello all, I am using the currency manager in VB to navigate a dataset. I know how to use .position to loop through the rows, but what I want to do is *get* the position of the row I just...
7
by: Nitromuse | last post by:
What is the proper way to refer to a dataset as the collection in a For Each, Next Statement? I want to loop through a particular column in the dataset, I've tried the following with no sucess. ...
9
by: Tony Girgenti | last post by:
Hello I developed and tested a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1. It uses a web form. I tried doing this without any help, but i'm...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I created a simple dll in VB2005 to use ADO.Net -- oleDBDataAdapter to write data to an Excel file. The code (below) works fine from an Excel file (invoke the dll from Excel to write to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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...
0
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,...

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.