473,224 Members | 1,603 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,224 software developers and data experts.

customer objects from datareader to BindingList<Customer>

The data access layer below returns, well, a mess as you can see on the last
line of this posting. What is the best way to return customer objects via a
datareader from the data layer into my view and bind them to a datagrid
using BindingList. I am in need of an epiphany here. Thank you. -Greg

******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID
************************
private Customer[] c;
c = BankTellerDataAccess.SqlHelper.ExecuteNonQuery();
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
for (int i = 1; i <= 100; i++)
{
bList.Add(new Customer(c.ID, c.FirstName, c.LastName, c.Address1,);
}
bs.DataSource = bList;
dataGridView1.DataSource = bs;

******************FROM DATA ACCESS LAYER ************************
ArrayList arr = new ArrayList();

---datareader sets ID, FirstName, variables to values from database)

Customer o = new Customer(ID,FirstName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(typeof(Customer));
Jan 24 '06 #1
4 3475
hazz wrote:
The data access layer below returns, well, a mess as you can see on
the last line of this posting. What is the best way to return
customer objects via a datareader from the data layer into my view
and bind them to a datagrid using BindingList. I am in need of an
epiphany here. Thank you. -Greg

******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID
************************
private Customer[] c;
c = BankTellerDataAccess.SqlHelper.ExecuteNonQuery();
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
for (int i = 1; i <= 100; i++)
{
bList.Add(new Customer(c.ID, c.FirstName, c.LastName, c.Address1,);
}
bs.DataSource = bList;
dataGridView1.DataSource = bs;

******************FROM DATA ACCESS LAYER ************************
ArrayList arr = new ArrayList();

---datareader sets ID, FirstName, variables to values from database)

Customer o = new Customer(ID,FirstName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(typeof(Customer));


You could try:

public List<Customer> GetCustomers()
{
List<Customer> toReturn = new List<Customer>();
// read datareader into Customer instances and add them to toReturn
// ..

return toReturn;
}

and in your bind routine:

private List<Customer> customers =
BankTellerDataAccess.SqlHelper.ExecuteNonQuery();

BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>(customers);
bs.DataSource = bList;
dataGridView1.DataSource = bs;

FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jan 24 '06 #2
Thank you so, so, so much Frans. I am studying that now. It really is a
shift for me so your help is much appreciated. I will reply back with
results. -Greg

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
hazz wrote:
The data access layer below returns, well, a mess as you can see on
the last line of this posting. What is the best way to return
customer objects via a datareader from the data layer into my view
and bind them to a datagrid using BindingList. I am in need of an
epiphany here. Thank you. -Greg

******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID
************************
private Customer[] c;
c = BankTellerDataAccess.SqlHelper.ExecuteNonQuery();
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
for (int i = 1; i <= 100; i++)
{
bList.Add(new Customer(c.ID, c.FirstName, c.LastName, c.Address1,);
}
bs.DataSource = bList;
dataGridView1.DataSource = bs;

******************FROM DATA ACCESS LAYER ************************
ArrayList arr = new ArrayList();

---datareader sets ID, FirstName, variables to values from database)

Customer o = new Customer(ID,FirstName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(typeof(Customer));


You could try:

public List<Customer> GetCustomers()
{
List<Customer> toReturn = new List<Customer>();
// read datareader into Customer instances and add them to toReturn
// ..

return toReturn;
}

and in your bind routine:

private List<Customer> customers =
BankTellerDataAccess.SqlHelper.ExecuteNonQuery();

BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>(customers);
bs.DataSource = bList;
dataGridView1.DataSource = bs;

FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Jan 24 '06 #3
works beautfully Frans! Thank you so much.
My next task is to find out how to edit the Customer items in the grid and
how List<T> handles that on updates or if I use something else.
This is working within the context of the Composite UI app block and will be
using Windows Communication Foundation for access to the database.
Thanks again!

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
hazz wrote:
The data access layer below returns, well, a mess as you can see on
the last line of this posting. What is the best way to return
customer objects via a datareader from the data layer into my view
and bind them to a datagrid using BindingList. I am in need of an
epiphany here. Thank you. -Greg

******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID
************************
private Customer[] c;
c = BankTellerDataAccess.SqlHelper.ExecuteNonQuery();
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
for (int i = 1; i <= 100; i++)
{
bList.Add(new Customer(c.ID, c.FirstName, c.LastName, c.Address1,);
}
bs.DataSource = bList;
dataGridView1.DataSource = bs;

******************FROM DATA ACCESS LAYER ************************
ArrayList arr = new ArrayList();

---datareader sets ID, FirstName, variables to values from database)

Customer o = new Customer(ID,FirstName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(typeof(Customer));


You could try:

public List<Customer> GetCustomers()
{
List<Customer> toReturn = new List<Customer>();
// read datareader into Customer instances and add them to toReturn
// ..

return toReturn;
}

and in your bind routine:

private List<Customer> customers =
BankTellerDataAccess.SqlHelper.ExecuteNonQuery();

BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>(customers);
bs.DataSource = bList;
dataGridView1.DataSource = bs;

FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Jan 24 '06 #4
The List<T> will be fine for its purpose, to create a list view essentially
from which rows will be selected to indicate the specific customer object to
bring up in a detail view. Updates of the model or business object can be
had via different means.

"hazz" <hazz@sonic_net> wrote in message
news:eK*************@TK2MSFTNGP12.phx.gbl...
works beautfully Frans! Thank you so much.
My next task is to find out how to edit the Customer items in the grid and
how List<T> handles that on updates or if I use something else.
This is working within the context of the Composite UI app block and will
be using Windows Communication Foundation for access to the database.
Thanks again!

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
hazz wrote:
The data access layer below returns, well, a mess as you can see on
the last line of this posting. What is the best way to return
customer objects via a datareader from the data layer into my view
and bind them to a datagrid using BindingList. I am in need of an
epiphany here. Thank you. -Greg

******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID
************************
private Customer[] c;
c = BankTellerDataAccess.SqlHelper.ExecuteNonQuery();
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
for (int i = 1; i <= 100; i++)
{
bList.Add(new Customer(c.ID, c.FirstName, c.LastName, c.Address1,);
}
bs.DataSource = bList;
dataGridView1.DataSource = bs;

******************FROM DATA ACCESS LAYER ************************
ArrayList arr = new ArrayList();

---datareader sets ID, FirstName, variables to values from database)

Customer o = new Customer(ID,FirstName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(typeof(Customer));


You could try:

public List<Customer> GetCustomers()
{
List<Customer> toReturn = new List<Customer>();
// read datareader into Customer instances and add them to toReturn
// ..

return toReturn;
}

and in your bind routine:

private List<Customer> customers =
BankTellerDataAccess.SqlHelper.ExecuteNonQuery();

BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>(customers);
bs.DataSource = bList;
dataGridView1.DataSource = bs;

FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


Jan 24 '06 #5

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

Similar topics

4
by: Ron Lounsbury | last post by:
I have a customer who has requested that I add "popup" text (a la ToolTips) to a couple of pulldown lists in a DHTML form we have in our project. He says - Just use the ALT tag. I went and double...
7
by: Jose Cuthberto | last post by:
WRAPPER CODE FOR A SET OF HTML FILES, AND BUTTON BAR LOOKS LIKE BELOW: |< < <> > >| => <= O' (magnifying glass for small gif text) I have a number of isolated html files for a 1000 page...
2
by: jd | last post by:
Hi, I have an xsl as below. I am trying to loop using <xsl:for-each> and in the select attribute of <xsl:for-each> i am getting the nodeset from the external javascript function in the <CDATA>...
1
by: Chuck | last post by:
I have a question tht I'm sure someone out there can answer. A friend of mine has developed an Access application that is a very business specific (niche type of application). The application...
0
by: Fasil | last post by:
Hi there I have a really anoying question, which is probably VS 2005, framework 2.0 specific. Usually when I connect a GridView or a DetailsView to a method in my business class for example...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
0
by: arunairs | last post by:
Hi, I am developing a web service which will be used in an intranet. I would like one of its methods to return a List<Customer>. Eventhough my web service contains a method : public...
2
by: David Thielen | last post by:
Hi; I have a small XML file that I need to read/change from my app. Is there some easy way to map from XML to my objects so I can just read it in to my objects, change the objects as needed,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.