473,320 Members | 1,978 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,320 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 3479
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,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.