08-20-2012, 12:07 PM
Hey guys, im trying to make a Class for the MySql Commands.
It worked but i have one Problem, how can i fill a listBox from a Class?
Someone send me a Code with a List but i dont understand it.
public List<string>[] Select()
{
Form1 f1 = new Form1();
string query = "SELECT * FROM `t_magic` `a_name` WHERE `a_index` = 48";
List<string>[] list = new List<string>[3];
list[0] = new List<string>();
list[1] = new List<string>();
list[2] = new List<string>();
if (this.OpenConnection() == true)
{
DataTable datatable = new DataTable();
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader dataReader = cmd.ExecuteReader();
this.connection.Close();
return list;
}
else
{
return list;
}
}
I wanna do it like this, but this is from the MainForm not from a Class.
DataTable datatable = new DataTable();
String sql1 = "SELECT * FROM t_characters a_index WHERE a_nick =" + textBox1.Text;
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(sql1, connection);
dataAdapter.Fill(datatable);
foreach (DataRow row in datatable.Rows)
{
ListViewItem item = new ListViewItem(
new string[] {
row["a_index"].ToString()});
listView1.Items.Add(item);
}

