473,490 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ADO.net question (access field with it's name).

Hi,

I have just started using ADO so this question may look a
bit dump.

I created a query and everything works fine.

ListViewItem iItem = null;
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data
Source=c:\\program files\\visual dataflex 8.2
\\bin\\pda\\pda.mdb");
OleDbCommand cmd = null;
OleDbDataReader rec1 = null;
conn.Open();
cmd = new OleDbCommand("select * from
pusers",conn);
rec1 = cmd.ExecuteReader();
while (rec1.Read())
{
iItem = new ListViewItem();
iItem.Text = rec1.GetValue(1).ToString
();
listView1.Items.Add(iItem);
}
The problem is this line "iItem.Text = rec1.GetValue
(1).ToString();"

is there a way by which instead of a field index I can use
the field name??
Thanks
Ivan Sammut
Nov 15 '05 #1
2 1605
Hi Ivan,

Before the loop you might retrieve column index by using GetOrdinal(string)
method.
Later you can use it for retrieving data.
And, btw, there is also a GetString method.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Ivan Sammut" <sa*****@nextgen.net.mt> wrote in message
news:04****************************@phx.gbl...
Hi,

I have just started using ADO so this question may look a
bit dump.

I created a query and everything works fine.

ListViewItem iItem = null;
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data
Source=c:\\program files\\visual dataflex 8.2
\\bin\\pda\\pda.mdb");
OleDbCommand cmd = null;
OleDbDataReader rec1 = null;
conn.Open();
cmd = new OleDbCommand("select * from
pusers",conn);
rec1 = cmd.ExecuteReader();
while (rec1.Read())
{
iItem = new ListViewItem();
iItem.Text = rec1.GetValue(1).ToString
();
listView1.Items.Add(iItem);
}
The problem is this line "iItem.Text = rec1.GetValue
(1).ToString();"

is there a way by which instead of a field index I can use
the field name??
Thanks
Ivan Sammut

Nov 15 '05 #2
Just as a note the datareader also has an indexer, so just
reference as follows:
iItem.Text = rec1.["fieldname"].ToString();

hth
Chris Torgerson
"Ivan Sammut" <sa*****@nextgen.net.mt> wrote in message
news:04****************************@phx.gbl...
Hi,

I have just started using ADO so this question may look a
bit dump.

I created a query and everything works fine.

ListViewItem iItem = null;
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data
Source=c:\\program files\\visual dataflex 8.2
\\bin\\pda\\pda.mdb");
OleDbCommand cmd = null;
OleDbDataReader rec1 = null;
conn.Open();
cmd = new OleDbCommand("select * from
pusers",conn);
rec1 = cmd.ExecuteReader();
while (rec1.Read())
{
iItem = new ListViewItem();
iItem.Text = rec1.GetValue(1).ToString
();
listView1.Items.Add(iItem);
}
The problem is this line "iItem.Text = rec1.GetValue
(1).ToString();"

is there a way by which instead of a field index I can use
the field name??
Thanks
Ivan Sammut

Nov 15 '05 #3

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

Similar topics

2
4123
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
8
3971
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
1
3768
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a...
13
3956
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
4
6361
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
4
2753
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
4
2308
by: BarryB | last post by:
I imported a large table of classes, teachers and students from Excel to MS Access. Up to a point, this worked out ok. Unfortunately, the students are represented as field names (Smith_Abigail,...
0
7524
MMcCarthy
by: MMcCarthy | last post by:
The more data you include in your tables the more you will need to have indexes to search and sort that data. However, there is a balance between having enough indexes and too many. Too many...
10
409
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Thank you for that. It was very...
2
19391
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
7112
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
7183
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
7356
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
5448
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,...
1
4878
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
4573
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
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
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 ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.