Witam, mam mały problem z ogarnięciem Readera, jak sądzę.
Utworzyłem następującą klasę:
class Baza
{
private string connection;
private SqlCommand command;
public SqlDataReader dr;
public SqlDataReader baza(string nowe_polecenie)
{
{
this.connection = "blabla";
string polecenie = nowe_polecenie;
this.command = new SqlCommand(polecenie, new SqlConnection(connection));
this.dr = null;
try
{
this.command.Connection.Open();
this.dr = this.command.ExecuteReader();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return null;
}
}
public void close()
{
this.dr.Close();
this.command.Connection.Close();
}
}
którą gdzieś tam w kodzie wywołuję:
Baza obiekt = new Baza();
obiekt.baza("select typ from coto");
comboBox_typ.Items.Add(obiekt.dr[0]);
obiekt.close();
Mam problem z linią comboBox_typ.Items.Add(obiekt.dr[0]); - generuje błąd i wysypanie programu. Zapewne mam tutaj namieszane ze składnią, umiałby mi ktoś poradzić, jak to poprawnie złożyć? Byłbym bardzo wdzięczny.