?
Solved

asp.net code

Posted on 2014-09-11
6
Medium Priority
?
227 Views
Last Modified: 2014-09-12
The aspx front end just show same record in the whole list. It is supposed to be all differen brand name from the access db. Need experts to take a look codes and see what is wrong ?
Thanks

//======asp.net c# front end ============================
  ServiceContract.Service s = new ServiceContract.Service();
            test.DataSource = s.GetBrandList();
           
            test.DataBind();
//===================================================

public IEnumerable<ServiceLibs.Brand> GetBrandList()
        {
            List<ServiceLibs.Brand> str = new List<ServiceLibs.Brand>();
            ServiceLibs.Brand brand = new ServiceLibs.Brand();
            try
            {
                using (OleDbConnection Connect = new OleDbConnection(DataConnection.OleDataCon.ToString()))
                {
                    string strItems = "SELECT distinct brandname from brand where brandname <> 'N/A' and brandname <> 'All Brand' order by brandname asc;";
                    OleDbCommand cmd = new OleDbCommand(strItems, Connect);
                    Connect.Open();
                    OleDbDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        brand.name = rdr["brandname"].ToString();
                        brand.id = 1;
                        str.Add(brand);                      
                    }
                 
                }                
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong in the query/database connection: ", ex);
            }
            return str;
        }
0
Comment
Question by:ITsolutionWizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40318472
Hi ITsolutionWizard;

I suspect that the class Brand represented by  ServiceLibs.Brand does not have public properties for the values being displayed in the ListBox and what you are most likely are seeing is the class name being repeatedly displayed. but this is difficult to say as you would need to post the ServiceLibs.Brand class. You have a couple of options here, you can add public properties for the fields or you can override the ToString method and return the name field.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40318519
Why are you giving every brand a same id? i.e. brand.id = 1;
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40318579
the brand.id is just for my test. You don't have to worry about it.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40319079
Please post the brand class.
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40319382
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ServiceLibs
{
    public class Brand
    {
        public int? id { get; set; }
        public string name { get; set; }
    }
}


Brand class above
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40319410
Hi ITsolutionWizard;

Move this Brand object from the top of the code to where I show it in the code below.

while (rdr.Read())
{
    // You need to create a new Brand object for each row you read from the reader 
    // otherwise you are adding the same object over and over again.
    ServiceLibs.Brand brand = new ServiceLibs.Brand();
    brand.name = rdr["brandname"].ToString();
    brand.id = 1;
    str.Add(brand);                       
}

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question