Du bastelst dort einen Datumswert in einen SQL string. Sowas ist generell die falsche Herangehensweise, bei Datumswerten forderst du den nächsten Bug aufgrund von unterschiedlichen Regionaleinstellungen förmlich heraus.
Außerdem sind Connection, Command und Reader nicht umsonst IDisposable. Rufst du kein Dispose auf[meta]direkt per try-finally, oder praktischerweise mit einem using-Block[/meta], hast du ein MemLeak.
Hier mal ein Bleistift, wie du es lösen könntest:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
| static BlpDings[] GetBlpDaten(DateTime livDatum) {
const string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=blp.mdb;"; const string selectBlpDatenSql = "SELECT DISTINCT Tage\n" + " ,Name\n" + "FROM BlpDaten\n" + "WHERE Von = :LivDatum and\n" + " Zimmer = 100";
using (IDbConnection connection = new OleDbConnection(connectionString)) using (IDbCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = selectBlpDatenSql;
IDataParameter livDatumParameter = command.CreateParameter();
livDatumParameter.DbType = DbType.Date; livDatumParameter.Value = livDatum;
command.Parameters.Add(livDatum);
using (IDataReader reader = command.ExecuteReader()) { if (!reader.IsClosed) { List<BlpDings> blpDaten = new List<BlpDings>(); while (reader.Read()) { int tage = reader.GetInt32(0); string name = reader.GetString(1);
blpDaten.Add(new BlpDings(tage, name));
}
BlpDings[] result = new BlpDings[blpDaten.Count];
blpDaten.CopyTo(result); return result; } } } return new BlpDings[0]; } |
An die listBox bekommst du es so:
listBox.DataSource = GetBlpDaten(iregndeinDatumsWert);
Hier noch die Klasse, die einem Datesatz entspricht:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
| class BlpDings { int tage; string name;
public int Tage { get { return tage; } set { tage = value; } }
public string Name { get { return name; } set { name = value; } }
public BlpDings(int tage, string name) { this.name = name; this.tage = tage; }
public override string ToString() { return string.Format("{0} ({1} Tage)", name, tage); } } |
Sorry, dass ich dir dass nur so hinschludere...
Schaue es dir an[meta]unbekannte dinge bitte auch in der SDK Dku nachschlagen[/meta] und frage wo der der Schuh drückt , wenn er überhaupt drückt. Ich schaue nacher/heute abend nochmal vorbei und werde drauf eingehen.