Code des Forms dass nicht geöffnet werdn will: 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 MySql.Data; using MySql.Data.MySqlClient;
namespace PHs_Teammanager { public partial class frmAliasVerbindung : Form { public frmAliasVerbindung() { InitializeComponent(); }
private void frmAliasVerbindung_Load(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
try
{
conn.Open();
}
catch
{
MessageBox.Show(this, "Es konnte keine Datenbankverbindung hergestellt werden.\n", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = conn;
myCommand.CommandText = "SELECT *****FROM `*****`";
//Query Starten
myAdapter.SelectCommand = myCommand;
MySqlDataReader reader_ol = myCommand.ExecuteReader();
while (reader_ol.Read())
{
listBox1.Items.Add(reader_ol.GetString("*****"));
}
reader_ol.Close();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
lblUsr.Text = listBox1.SelectedItem.ToString();
listBox2.Items.Add(lblUsr.Text);
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
try
{
conn.Open();
}
catch
{
MessageBox.Show(this, "Es konnte keine Datenbankverbindung hergestellt werden.\n", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = conn;
myCommand.CommandText = "SELECT alias FROM `***` WHERE `taeter` ="+lblUsr.Text+";";
//Query Starten
myAdapter.SelectCommand = myCommand;
MySqlDataReader reader_ol = myCommand.ExecuteReader();
while (reader_ol.Read())
{
listBox2.Items.Add(reader_ol.GetString("alias"));
}
reader_ol.Close();
}
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = myConnectionString;
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
//string insertQuery = "INSERT INTO `***` (`id`, `name`, `cop_seit`, `rang`, `forenlink`, `last_activity`, `anderes`, `profile_url`) VALUES ('"+txtID.Text+"', '" + txtName.Text + "', '" + txtCopseit.Text + "', '" + txtRang.Text + "', '" + txtForenlink.Text + "', '', '" + txtAnderes.Text + "', '" + txtAvatar.Text + "');";
string insertQuery = "UPDATE `phs_blacklist` SET `alias` = '" + listBox2.Items.ToString() + "' WHERE `taeter` =" + lblUsr.Text + ";";
MySqlCommand myCommand = new MySqlCommand(insertQuery, conn);
//myCommand.CommandText = "INSERT INTO `phs_team` (`id`, `name`, `cop_seit`, `rang`, `forenlink`, `last_activity`, `anderes`, `profile_url`) VALUES (NULL, '"+txtName.Text+"', '"+txtCopseit.Text+"', '"+txtRang.Text+"', '"+txtForenlink.Text+"', '', '"+txtAnderes.Text+"', '"+txtAvatar.Text+"');";
try
{
conn.Open();
}
catch
{
MessageBox.Show(this, "Es konnte keine Datenbankverbindung hergestellt werden.\n", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
myCommand.ExecuteNonQuery();
conn.Close();
MessageBox.Show(this, "Änderungen erfolgreich in der Datenbank gespeichert!", "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
Code vom ausgangsform: private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex == 0) { Teamlisteneditor frm = new Teamlisteneditor(); frm.Show(); } if (comboBox1.SelectedIndex == 1) { BlackListReport frm = new BlackListReport(); fr