Wie die Überschrift schon sagt, ich bekomms nicht hin variablen zu benutzen und hab bisher noch nix gefunden was mir weiter hilft.
Code:
private void comboBox1_SelectedValueChanged(object sender, EventArgs e) //Auslesen Planeten von Systeme aus ComoboBox 1 und zu ComboBox 2 addieren.
{
MySqlConnection connection = new MySqlConnection(dbconnect);
MySqlCommand cmd = connection.CreateCommand();
MySqlDataReader Reader;
anz = 0;
int sid = comboBox1.SelectedIndex;
sid = +1;
int cid = 0;
string row;
comboBox2.Items.Clear();
cmd.CommandText = "SELECT * FROM planeten where planetsid =3"; hier möchte anstatt der 3 ne Variable benutzen für die ID
connection.Open();
Reader = cmd.ExecuteReader();
while (Reader.Read())
{
string name = "anzahl";
anz = (int)Reader[name];
}
do // Planeten Namen nach Anzahl zur ComboBox2
{
planet = "planetencol" + cid;
row = (string)Reader[planet];
comboBox2.Items.Add(row);
++cid;
}
while (cid < anz);
connection.Close();