471,605 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 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 3319
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ron Lounsbury | last post: by
7 posts views Thread by Jose Cuthberto | last post: by
reply views Thread by Fasil | last post: by
17 posts views Thread by roN | last post: by
reply views Thread by arunairs | last post: by
2 posts views Thread by David Thielen | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

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.