Listbox problem igen.
Jeg har nu fået hul igennem til min access database og kan hente data ind i listbox'en via tryk på knapperne. Hvis jeg nu trykker på den første knap som er "Titel" får jeg hele listen i min listbox, men ville også gerne at jeg ku få kolonnen "Antal Min" der svarer til Titel'erne i min database ind og vises i listbox'en sammen med Titel ( Altså så Antal min står til højre for Titel ). Hvordan kan jeg gøre dette når min kode er fl.g : ?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DatabaseEksempel
{
public partial class Boxset : Form
{
public Boxset()
{
InitializeComponent();
}
private void btn_Click(object sender, EventArgs e)
{
lb.Items.Clear();
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Lars\Dokumenter\Filmliste3.mdb");
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM Ark1";
dbReader = cmd.ExecuteReader();
string Titel;
while (dbReader.Read())
{
Titel = dbReader.GetValue(3).ToString();
lb.Items.Add(Titel);
}
dbReader.Close();
Myconnection.Close();
}
private void button2_Click(object sender, EventArgs e)
{
lb.Items.Clear();
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Lars\Dokumenter\Filmliste3.mdb");
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM Ark1";
dbReader = cmd.ExecuteReader();
string Titel;
while (dbReader.Read())
{
Titel = dbReader.GetValue(6).ToString();
lb.Items.Add(Titel);
}
dbReader.Close();
Myconnection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
lb.Items.Clear();
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Lars\Dokumenter\Filmliste3.mdb");
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM Ark1";
dbReader = cmd.ExecuteReader();
string Titel;
while (dbReader.Read())
{
Titel = dbReader.GetValue(15).ToString();
lb.Items.Add(Titel);
}
dbReader.Close();
Myconnection.Close();
}
private void button3_Click(object sender, EventArgs e)
{
lb.Items.Clear();
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Lars\Dokumenter\Filmliste3.mdb");
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM Ark1";
dbReader = cmd.ExecuteReader();
string Titel;
while (dbReader.Read())
{
Titel = dbReader.GetValue(12).ToString();
lb.Items.Add(Titel);
}
dbReader.Close();
Myconnection.Close();
}
}
}