473,734 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

customer objects from datareader to BindingList<Cus tomer>

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 = BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();
BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>();
// 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.D ataSource = bs;

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

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

Customer o = new Customer(ID,Fir stName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(ty peof(Customer)) ;
Jan 24 '06 #1
4 3521
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 = BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();
BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>();
// 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.D ataSource = bs;

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

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

Customer o = new Customer(ID,Fir stName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(ty peof(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 =
BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();

BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>(customer s);
bs.DataSource = bList;
dataGridView1.D ataSource = 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.n l> wrote in message
news:xn******** *******@news.mi crosoft.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 = BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();
BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>();
// 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.D ataSource = bs;

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

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

Customer o = new Customer(ID,Fir stName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(ty peof(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 =
BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();

BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>(customer s);
bs.DataSource = bList;
dataGridView1.D ataSource = 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.n l> wrote in message
news:xn******** *******@news.mi crosoft.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 = BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();
BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>();
// 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.D ataSource = bs;

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

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

Customer o = new Customer(ID,Fir stName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(ty peof(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 =
BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();

BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>(customer s);
bs.DataSource = bList;
dataGridView1.D ataSource = 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******** *****@TK2MSFTNG P12.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.n l> wrote in message
news:xn******** *******@news.mi crosoft.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 = BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();
BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>();
// 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.D ataSource = bs;

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

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

Customer o = new Customer(ID,Fir stName, LastName, Address1);
arr.Add(o);
return (Customer[])arr.ToArray(ty peof(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 =
BankTellerDataA ccess.SqlHelper .ExecuteNonQuer y();

BindingSource bs = new BindingSource() ;
BindingList<Cus tomer> bList = new BindingList<Cus tomer>(customer s);
bs.DataSource = bList;
dataGridView1.D ataSource = 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
6492
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 checked, and the ALT property only shows up for the IMG tag. Can anyone help me with how to implement this? What they want is some amplification to the list selections. TIA Ron Lounsbury
7
3002
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 html document. The .htm files have associated gifs, anchors, using NAME and HREF attributes. The htmls are all flat, ie in the same directory but they are named like chapsec_subsec_page.htm, specifically, a1_1_page_20.htm. The gifs are in a separate...
2
7209
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> section. This code works fine with MSXML4.0 parser. When I try to use .Net, it gives me error saying " The expression passed to this method should result in a NodeSet."
1
1554
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 would only be used by one type of business but there are a lot of these businesses out there along without too much competition. He is interested in selling the application (a runtime version of Access would be supplied as well) but he works...
0
1353
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 UpdateCustomerData(string name, int age, original_id), my GridView automatically creates the <UpdateParameters>
17
4848
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 Page Is Valid XHTML 1.0 Transitional!" but it still wouldn't look the same. It is on http://www.dvdnowkiosks.com/new/theproduct.php scroll down and recognize the black bottom bar when you go ewith firefox(2.0) which isn't there with IE7. Why does...
11
76229
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 else who got stumped like I did. It seems so simple... binding a DataGridView to a List<T>. These are the two general problems that I kept running into: (1) When the data in the list updated, the data on the screen did not update. (2) When I...
0
2440
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 List<CustomerGetAllCustomers() { CustomerRepository repo = new CustomerRepository(); ISelectionCommandFactory<stringfact = new
2
4901
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, then write the whole thing back out? thanks - dave david@at-at-at@windward.dot.dot.net
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9184
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6737
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6033
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4551
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.