Solved

asp.net code

Posted on 2014-09-11
6
216 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
  • 3
  • 2
6 Comments
 
LVL 62

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
 

Author Comment

by:ITsolutionWizard
ID: 40318579
the brand.id is just for my test. You don't have to worry about it.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 62

Expert Comment

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

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 62

Accepted Solution

by:
Fernando Soto earned 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now