Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC4-Jan-11 13:21
LAPEC4-Jan-11 13:21 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC4-Jan-11 14:02
LAPEC4-Jan-11 14:02 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? [modified] Pin
Henry Minute5-Jan-11 9:03
Henry Minute5-Jan-11 9:03 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC5-Jan-11 13:15
LAPEC5-Jan-11 13:15 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute5-Jan-11 13:17
Henry Minute5-Jan-11 13:17 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC5-Jan-11 13:23
LAPEC5-Jan-11 13:23 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute5-Jan-11 13:24
Henry Minute5-Jan-11 13:24 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 2:32
LAPEC6-Jan-11 2:32 
Hi Henry

I want to explain the prblem I'm having with datagridview...

-Run the application that I send it to you,
-Click on the SignIn Button to jump to the next form,
-At the bottom of this form there is a Button called Manage,
-Click on it to call that form,
Now, on this form there is a Button called Stock In, if you click on this button it calls the form called StockIn form.
As you can see, the controls of this form are:
-food & drink Buttons (corresponding to the food and drink menu),
-four other buttons to scroll up and down (these buttons are not important at this moment), and
-dataGridView.
What I want to do here in this form is:
-When I click the Starter button I want to display only the starters on the datagridview (so far I have managed to do that 'see the code below')

private DataGridViewTextBoxColumn ColFoodQtyStock = new DataGridViewTextBoxColumn();
        private DataGridViewTextBoxColumn ColFoodStatus = new DataGridViewTextBoxColumn();
        
        private void cmdStarters_Click(object sender, EventArgs e)
        {
            OleDbConnectionStringBuilder connBuilder = new OleDbConnectionStringBuilder();
            connBuilder.DataSource = @"C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposMenu.accdb";
            connBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
            connBuilder.Add("Jet OLEDB:Engine Type", "5");

            // Food SQL Query
            string foodTypeSql = @"SELECT FoodName, FoodType FROM Food WHERE FoodType = @foodType";
            using (OleDbConnection conn = new OleDbConnection(connBuilder.ConnectionString))
            {
                dataGridView1.Columns.Clear();
                dataGridView1.RowTemplate.Height = 60;
                //====================================\\
                dataGridView1.Visible = true;
                dataGridView2.Visible = false;
                try
                {
                    OleDbCommand foodsCommand = new OleDbCommand(foodTypeSql, conn);
                    OleDbParameter foodType = foodsCommand.Parameters.Add("@foodType", OleDbType.VarChar, 15);
                    OleDbDataAdapter foodsDa = new OleDbDataAdapter(foodsCommand);
                    DataRow dr;
                    DataSet ds = new DataSet();
                    conn.Open();
                    foodType.Value = "Starter";
                    foodsDa.Fill(ds, "Food_table");
                    conn.Close();
                    dataGridView1.DataSource = ds;
                    dataGridView1.DataMember = "Food_table";

                    dataGridView1.Columns.AddRange(ColFoodQtyStock, ColFoodStatus);
                    
                    DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
                    this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
                    dataGridViewCellStyle1.Font = new Font("Verdana", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                    this.dataGridView1.Columns[0].Width = 420;
                    this.dataGridView1.Columns[1].Width = 180;
                    this.dataGridView1.Columns[2].Width = 300;
                    this.dataGridView1.Columns[3].Width = 308;

                    // ColStatus 
                    ColFoodStatus.HeaderText = "Status";
                    ColFoodStatus.Name = "ColFoodStatus";

                    // ColQtyStock
                    ColFoodQtyStock.HeaderText = "Quantity In Stock";
                    ColFoodQtyStock.Name = "ColFoodQtyStock";
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex);
                }
            }
        }

And here is what it looks like the dataGridView...
===============================================================
FoodName     FoodType     Qty In Stock     Status
===============================================================
Olives       Starter                      
Soup         Starter                      
etc...       etc...                  
===============================================================


The columns FoodName & FoodType are generated from the database, and the columns Qty In Stock & Status are genereated at a run time.

Now how can I add data in the columns Qty In Stock & Status at the run time (see the datagridview below)

===============================================================
FoodName     FoodType     Qty In Stock     Status
===============================================================
Olives       Starter      0                <Allways on Stock>
Soup         Starter      0                <Allways on Stock>
etc...       etc...       etc...           etc...
===============================================================


There is more to ask you later what else I want to do but for the moment I want to do just this....

Henry this is a very long question and I hope is clear and understandable to you.

Thanks in advance


kind regards


Roni
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 4:36
Henry Minute6-Jan-11 4:36 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 6:01
LAPEC6-Jan-11 6:01 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 8:29
Henry Minute6-Jan-11 8:29 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 8:35
LAPEC6-Jan-11 8:35 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 11:04
Henry Minute6-Jan-11 11:04 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 11:28
LAPEC6-Jan-11 11:28 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 11:29
Henry Minute6-Jan-11 11:29 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 11:32
LAPEC6-Jan-11 11:32 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 11:57
LAPEC6-Jan-11 11:57 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 12:00
Henry Minute6-Jan-11 12:00 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 12:04
LAPEC6-Jan-11 12:04 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 13:07
Henry Minute6-Jan-11 13:07 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 13:23
LAPEC6-Jan-11 13:23 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute6-Jan-11 14:19
Henry Minute6-Jan-11 14:19 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC6-Jan-11 15:13
LAPEC6-Jan-11 15:13 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
Henry Minute7-Jan-11 11:16
Henry Minute7-Jan-11 11:16 
GeneralRe: C# - How to call database records one-by-one and display it in ListView? Pin
LAPEC7-Jan-11 13:21
LAPEC7-Jan-11 13:21 

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.