473,466 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I pass one record, one row to a Method?

Win32 C++/Delphi Developer here moving to .NET C# (Yes, I'm a newbie
again)

Thank you all for any replies in advance.

I am developing a class that accesses a record, one record, and sets
the Row values into a Properties, this is of course is based on many
conditions, there is a lot of data validation etc in there before the
property is set, thus this method is required. I have developed this
because we have to access this method from all over the place.

I developed this method passing in a RecordID, got the record then did
my stuff, great it all works!

The Problem:
I want to be able to use this Method say in a while loop from a Query
sending each row to the method and reading the properties..

The Newbie Question:
How do I pass one record, one row to a Method?
and
How do i access the individual fields by name after passed to the
method?

Oct 4 '06 #1
4 10091
The first thing depend on wich type of DataStore you are using into your
application. For example if you are using DataTable and you want to pass a
valid row

private void pass(DataTableRow row)
{
//here you must retreive data
String field = row["Field_name"].ToString();
}

"DaBrain" wrote:
Win32 C++/Delphi Developer here moving to .NET C# (Yes, I'm a newbie
again)

Thank you all for any replies in advance.

I am developing a class that accesses a record, one record, and sets
the Row values into a Properties, this is of course is based on many
conditions, there is a lot of data validation etc in there before the
property is set, thus this method is required. I have developed this
because we have to access this method from all over the place.

I developed this method passing in a RecordID, got the record then did
my stuff, great it all works!

The Problem:
I want to be able to use this Method say in a while loop from a Query
sending each row to the method and reading the properties..

The Newbie Question:
How do I pass one record, one row to a Method?
and
How do i access the individual fields by name after passed to the
method?

Oct 4 '06 #2
It sounds like you are filling objects from a database - in which case I
would tend to use a DataReader... this provides access to each row (in turn,
forwards only), and access to the values within that row either by name or
ordinal. Perhaps google for some SqlDataReader examples?

Marc
Oct 4 '06 #3
How do I pass one record, one row to a Method?
and
How do i access the individual fields by name after passed to the
method?
The key is to understand the OOP model of a DataSet. A DataSet includes
a number of possible objects, some of which can be DataTables. A
DataTable includes a collection of rows and columns. You often don't
need a full DataSet, especially in ADO.NET 2.0, since a single
DataTable often has the functionality you need.

A DataTable contains both DataRows and DataColumns. One oddity of
ADO.NET is that a DataRow is NOT a collection of DataColumns, and this
is where most Delphi coders have a problem at first. A DataRow can't
stand alone: it only has a meaning in the context of a DataTable.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Create a table using the DataTable(string TableName)
constructor
DataTable dt = new DataTable("Employees");

// Add 2 columns to the table
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("Name", typeof(string));

// Add a primary key based on a column
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };

// Now create some new rows with data in the new columns
DataRow dr;

dr = dt.NewRow();
dr["ID"] = 600040;
dr["Name"] = "Smith";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["ID"] = 205;
dr["Name"] = "Jones";
dt.Rows.Add(dr);

// Iterate over the rows of the table - this shows how to pass
rows to another function
foreach (DataRow row in dt.Rows)
showRow(dt, row);
}

private static void showRow(DataTable dt, DataRow row)
{
// now iterate over the columns in a single row
foreach (DataColumn dc in dt.Columns)
Console.WriteLine("Column: {0}, value: {1}", dc.ColumnName,
row[dc].ToString());
Console.WriteLine(""); // blank line after each row
}
}
}

Oct 4 '06 #4

If you go to
http://sholliday.spaces.live.com/?_c...26ayear%3d2006
or
http://sholliday.spaces.live.com/ and find the May 2006 blog entry.

Download the code.

And look for thsi method:
private Collections.CustomerCollection SerializeCustomers(IDataReader
dataReader, bool deep)
{
}
Notice this is private. Basically, I have a common method to create a
Collection, but the dataReader could have 1 , 100 , 1000 Customers in it.
The method which calls this method decides how to populate the dataReader.
As far as accessing the fields by name, find the code for the SafeDataReader
http://www.lhotka.net/Article.aspx?i...3-8b5bda6bad22
and
http://www.lhotka.net/cslanet/download10.aspx
Again, if you get the code (from my blog), you can see the concept in
action, where SerializeCustomers is reused over and over again.



"DaBrain" <Ta**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Win32 C++/Delphi Developer here moving to .NET C# (Yes, I'm a newbie
again)

Thank you all for any replies in advance.

I am developing a class that accesses a record, one record, and sets
the Row values into a Properties, this is of course is based on many
conditions, there is a lot of data validation etc in there before the
property is set, thus this method is required. I have developed this
because we have to access this method from all over the place.

I developed this method passing in a RecordID, got the record then did
my stuff, great it all works!

The Problem:
I want to be able to use this Method say in a while loop from a Query
sending each row to the method and reading the properties..

The Newbie Question:
How do I pass one record, one row to a Method?
and
How do i access the individual fields by name after passed to the
method?

Oct 4 '06 #5

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

Similar topics

2
by: Ben | last post by:
Hi, When clicking on a button, a new record must be created in an Access table. See my code: <% set objdc = Server.CreateObject("ADODB.Connection")...
1
by: Luke Airig | last post by:
I am using the Saxon 6.5.3 engine and I have an xsl stylesheet that merges two files on a date_time field and writes out a tab-delimited flat file. My working version has a hard-coded file name in...
11
by: lokb | last post by:
Hi, I have a structure which and defined a smart pointer to the structure. /* Structure of Begin Document Index Record */ typedef struct BDI_Struct{ unsigned char rname; unsigned short int...
1
by: TErnst | last post by:
Hello All.... What I am attempting to do is have a link/button on a page (testpopup.cfm) that opens a popup page (popupwindow.cfm). The popup page displays a resultset from a query and the...
3
by: Don Seckler | last post by:
I have a data entry form called Draw. This form is used to enter data in the table called Draw. The table has the following fields: WholesalerID, MagID, IssueID, CopiesDist, and the index is...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
1
by: Hexman | last post by:
Hello Again, I have a table that contains data that needs to be ranked. There are actually 2 columns that need to be ranked. I have already completed the task but did it in a "Brute Force" way....
2
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I need to parse XML file and I found a solution in some book on PHP5 ("PHP5 Programming" by Rasmus Lerdors and others). Unfortunately I have two problems that I don't...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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,...
0
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
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
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 ...

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.