Click here to Skip to main content
16,015,518 members
Home / Discussions / C#
   

C#

 
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 
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 
Hi Luc

Ok I will try to explain based on my code.

- When Form1 Loads (see the code below I have created database connection)

public partial class DtposMDIParentSystem : Form
    {
        
        List<MenuItems>; menuItems = new List<MenuItems>();

        
        public DtposMDIParentSystem()
        {
            InitializeComponent();

            //create the database connection
            OleDbConnection aConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposDatabase.accdb;");

            //create the command object and store the sql query
            OleDbCommand aCommand = new OleDbCommand("SELECT * FROM Food", aConnection);

            try
            {
                aConnection.Open();

                //create the datareader object to connect to table
                OleDbDataReader reader = aCommand.ExecuteReader();
                while (reader.Read()) 
                {
                    MenuItems mi = new MenuItems();
                    mi.ItemName = reader["Name"].ToString();
                    mi.ItemPrice = Double.Parse(reader["Price"].ToString());

                    menuItems.Add(mi);
                }
                reader.Close();
                aConnection.Close();
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show("Invalid Masseage = " + ex.Message);
            } 
        }


- Clic the button1 (inside Form1) calls the UserControl1 and displays it into Form1 (see the code below)
UserControl1 userC = new UserControl();
//====================================\\
private void cmdStarters_Click(object sender, EventArgs e)
{
    this.StartersPanel.Visible = true;
    this.userC.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.userC.Location = new System.Drawing.Point(0, 0);
    this.userC.Size = new System.Drawing.Size(696, 556);
    this.userC.Enabled = true;
    this.userC.Visible = true;
    this.StartersPanel.Controls.Add(userC);
}

- The UserControl1 has 10 Buttons (such as cmdOlives, cmdSoup etc. etc...)
- Now when I click on:
- cmdOlives_Click event button I want to display rocord1 (such as Olives) from database table and display it into my TableOrderListView...
- Also when I click on:
- cmdSoup_Click event button I want to display rocord2 (such as Soup) from database table and display it into my TableOrderListView... and so on

like so

ListView
_________________________________________
Num Name Price
_________________________________________
1 Olives £2.95
1 Soup £4.95
. . .
. . .
. . .
_________________________________________

I hope i've explained so you could understand what im trying to do...

kind regards

Roni
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 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC19-Dec-10 1:15
LAPEC19-Dec-10 1:15 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute19-Dec-10 1:41
Henry Minute19-Dec-10 1:41 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC19-Dec-10 1:57
LAPEC19-Dec-10 1:57 

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.