Click here to Skip to main content
15,888,803 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trying to create a new array [modified] Pin
turbosupramk316-Dec-10 15:42
turbosupramk316-Dec-10 15:42 
GeneralRe: Trying to create a new array Pin
PIEBALDconsult16-Dec-10 16:37
mvePIEBALDconsult16-Dec-10 16:37 
AnswerRe: Trying to create a new array Pin
Hiren solanki16-Dec-10 19:07
Hiren solanki16-Dec-10 19:07 
QuestionC# - How to call database records one-by-one and display it in ListView? [modified] Pin
LAPEC16-Dec-10 10:50
LAPEC16-Dec-10 10:50 
AnswerRe: C# - How to call database records one-by-one and display it in ListView? Pin
Luc Pattyn16-Dec-10 11:06
sitebuilderLuc Pattyn16-Dec-10 11:06 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC16-Dec-10 11:12
LAPEC16-Dec-10 11:12 
AnswerRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute16-Dec-10 11:30
Henry Minute16-Dec-10 11:30 
AnswerRe: C# - How to call database records one-by-one and display it in ListView? Pin
Luc Pattyn16-Dec-10 11:36
sitebuilderLuc Pattyn16-Dec-10 11:36 
Hi again,

here are a few comments:

1.
I'm puzzled by your code.
AFAICT it should not even compile, as the "result" list is part of your DtposMDIParentSystem form, and not visible to your UserControl. How can it accept the if (result.Count > 0) line, it does not know about result??

2.
I've never used DbReader.GetValues, nor created an array of Object, like you do. I would rather have a struct or class (say FoodItem) that represents one row of your database table, and then create instances and fill them, one field at a time, using something like:
List<FoodItem> foodItems=new List<FoodItem>();
while (reader.Read()) {
    FoodItem fi=new FoodItem();
    fi.Name=reader["Name"];
    fi.Calories=int.Parse(reader["Calories"]);
    ...
    foodItems.Add(fi);
}

The advantage is all is fully typed, and all necessary conversions/parse operations are explicit.

3.
I would never create buttons one way (say with Visual Designer), and then try and match them up with a data structure that I obtain in another way (by reading a database). I'd rather just read the database and create the buttons (or whatever Controls are most suited) at run-time, so adding/removing a few FoodItems in the database is acceptable to the application as is.
FYI: Visual Designer stores all its stuff as regular C# code in a separate file, have a look; you can write similar code yourself, and have it execute when appropriate.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC16-Dec-10 12:21
LAPEC16-Dec-10 12:21 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Luc Pattyn16-Dec-10 12:26
sitebuilderLuc Pattyn16-Dec-10 12:26 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC16-Dec-10 12:59
LAPEC16-Dec-10 12:59 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Luc Pattyn16-Dec-10 13:26
sitebuilderLuc Pattyn16-Dec-10 13:26 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC16-Dec-10 13:32
LAPEC16-Dec-10 13:32 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute16-Dec-10 12:27
Henry Minute16-Dec-10 12:27 
AnswerRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute17-Dec-10 9:48
Henry Minute17-Dec-10 9:48 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC17-Dec-10 14:30
LAPEC17-Dec-10 14:30 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute17-Dec-10 14:40
Henry Minute17-Dec-10 14:40 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC17-Dec-10 14:56
LAPEC17-Dec-10 14:56 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute17-Dec-10 15:03
Henry Minute17-Dec-10 15:03 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute17-Dec-10 14:56
Henry Minute17-Dec-10 14:56 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC17-Dec-10 15:11
LAPEC17-Dec-10 15:11 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC18-Dec-10 12:28
LAPEC18-Dec-10 12:28 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute18-Dec-10 13:13
Henry Minute18-Dec-10 13:13 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC18-Dec-10 13:25
LAPEC18-Dec-10 13:25 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute19-Dec-10 0:35
Henry Minute19-Dec-10 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.