Hello, this is my code in visual c#:
namespace im_client
{
public partial class Form2 : Form
{
MySqlConnection conDatabase = new MySqlConnection("Data Source=86.123.220.28;" +
"Persist Security Info=yes;" +
"UserId=chat;PWD=123;Port=3306;Database=im_chat;") ;
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public Form2()
{
InitializeComponent();
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Interval = 1000;
myTimer.Start();
Application.DoEvents();
this.Text = Form1.usern+" - IM Chat";
}
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
populate();
arequest();
//addrequest();
}
public void populate()
{
MySqlCommand userlist_populate = new MySqlCommand("SELECT * FROM friendlist WHERE user=?user", conDatabase);
userlist_populate.Parameters.AddWithValue("?user", Form1.usern);
conDatabase.Open();
MySqlDataReader dataReader = userlist_populate.ExecuteReader();
if (dataReader.HasRows)
{
this.listBox1.Items.Remove("To add a friend press the + button");
while (dataReader.Read())
{
int index = this.listBox1.Items.IndexOf(dataReader.GetString(1 ));
if (index == -1)
{
this.listBox1.Items.Add(dataReader.GetString(1));
}
}
}
else
{
int index2 = this.listBox1.Items.IndexOf("To add a friend press the + button");
if (index2 == -1)
{
this.listBox1.Items.Add("To add a friend press the + button");
}
}
dataReader.Close();
conDatabase.Close();
}
public void arequest()
{
MySqlCommand userlist_add = new MySqlCommand("SELECT * FROM friendlist WHERE friend=?user AND invers='1'", conDatabase);
userlist_add.Parameters.AddWithValue("?user", Form1.usern);
conDatabase.Open();
MySqlDataReader dataReader = userlist_add.ExecuteReader();
if (dataReader.HasRows)
{
MessageBox.Show("Test");
//while (dataReader.Read())
//{
// Form5 form5 = new Form5(dataReader.GetString(0));
//form5.Show();
//}
}
dataReader.Close();
conDatabase.Close();
}
The problem is that it says the connection is already opened. i've tried different conections, different names for the MySqlDataReader object instances, nothing worked.... any suggestions?
10x!