473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Need help with multiple MySqlDataReader in c#

1
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!
Apr 2 '07 #1
1 3935
Motoma
3,237 Expert 2GB
What do you mean when you say your connection is already open? Could you post the error/exception messages you receive?
Apr 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
2
by: TSK | last post by:
I cannot get my focus() fn to work in my validateInput(userInput) fn. It will not allow the user to go back and correct invalid input like it should. Instead it goes right on through with the...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
0
by: wink martindale | last post by:
Hello, I am developing a vb.net application using a mySql database with corelabs provider. I am having a bit of difficulty getting a db connection to work. Here is my app.exe.config file: ...
0
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice...
0
by: luckilian | last post by:
Hi guys ... I'm new around here and i have a problem i'm trying to extract a datetime value from a mysql database.The feld is in format yyyy-mm-dd 00:00:00 and the datareader extracts something...
0
by: Teo | last post by:
Hi!! I have been trying to fix an error I keep getting on my VB.NET code. For some reason, I get an error saying "Invalid attempt to access a field before calling Read()" everytime. As you can see...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.