Hi guys,
I am having trouble extracting particular row information. My database consists of over 60 rows but everytime I try, it shows a particular row information.
What am I doing wrong?
Btn1.Text = reader["MenuDescription"].ToString(); I want this pull information from say row 99
Thanks
I am having trouble extracting particular row information. My database consists of over 60 rows but everytime I try, it shows a particular row information.
What am I doing wrong?
Btn1.Text = reader["MenuDescription"].ToString(); I want this pull information from say row 99
Thanks
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Menu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns.Add("MenuDescription", "Description");
dataGridView1.Columns.Add("MenuPrice", "Price");
OleDbConnection connect = new OleDbConnection(); //Creates the connection
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\chewj\Documents\Visual Studio 2012\Projects\Menu\Menu\POS.accdb;Persist Security Info=False;";
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "SELECT * FROM MenuInventory";
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Btn1.Text = reader["MenuDescription"].ToString();
Btn1.Image = Image.FromFile("C:\\Users\\chewj\\Documents\\Visual Studio 2012\\Projects\\Menu\\Menu\\Olive Garden\\Appetizer\\Caprese Flatbread.png");
dataGridView1.Rows.Add();
dataGridView1.Rows[0].Cells[0].Value = reader["MenuDescription"].ToString();
dataGridView1.Rows[0].Cells[1].Value = reader["MenuPrice"].ToString();
}
reader.Close();
connect.Close();
//MessageBox.Show("Connection Opened"); //Checks to see if the connection is established
}
}
}