473,944 Members | 21,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with multiple MySqlDataReader in c#

1 New Member
Hello, this is my code in visual c#:

namespace im_client
{
public partial class Form2 : Form
{
MySqlConnection conDatabase = new MySqlConnection ("Data Source=86.123.2 20.28;" +
"Persist Security Info=yes;" +
"UserId=chat;PW D=123;Port=3306 ;Database=im_ch at;");



System.Windows. Forms.Timer myTimer = new System.Windows. Forms.Timer();



public Form2()
{

InitializeCompo nent();



myTimer.Tick += new EventHandler(Ti merEventProcess or);
myTimer.Interva l = 1000;
myTimer.Start() ;
Application.DoE vents();

this.Text = Form1.usern+" - IM Chat";


}


private void TimerEventProce ssor(Object myObject, EventArgs myEventArgs)
{
populate();
arequest();
//addrequest();

}
public void populate()
{

MySqlCommand userlist_popula te = new MySqlCommand("S ELECT * FROM friendlist WHERE user=?user", conDatabase);
userlist_popula te.Parameters.A ddWithValue("?u ser", Form1.usern);

conDatabase.Ope n();

MySqlDataReader dataReader = userlist_popula te.ExecuteReade r();

if (dataReader.Has Rows)
{
this.listBox1.I tems.Remove("To add a friend press the + button");
while (dataReader.Rea d())
{

int index = this.listBox1.I tems.IndexOf(da taReader.GetStr ing(1));

if (index == -1)
{

this.listBox1.I tems.Add(dataRe ader.GetString( 1));

}


}

}
else
{
int index2 = this.listBox1.I tems.IndexOf("T o add a friend press the + button");
if (index2 == -1)
{
this.listBox1.I tems.Add("To add a friend press the + button");
}
}
dataReader.Clos e();
conDatabase.Clo se();


}

public void arequest()
{
MySqlCommand userlist_add = new MySqlCommand("S ELECT * FROM friendlist WHERE friend=?user AND invers='1'", conDatabase);
userlist_add.Pa rameters.AddWit hValue("?user", Form1.usern);
conDatabase.Ope n();
MySqlDataReader dataReader = userlist_add.Ex ecuteReader();
if (dataReader.Has Rows)
{
MessageBox.Show ("Test");
//while (dataReader.Rea d())
//{

// Form5 form5 = new Form5(dataReade r.GetString(0)) ;
//form5.Show();
//}

}


dataReader.Clos e();
conDatabase.Clo se();
}



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 3975
Motoma
3,237 Recognized Expert Specialist
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
2510
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 last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
2
4578
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 invalid input. I used this same function in another program similar to this one and it worked just fine, but it's not working in this one. Why? My code is included below. Your help will be greatly appreciated. <html> <head> <title>Syster...
10
2910
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 for multiple companies and work for multiple divisions within each company. Within each division he can work in multiple departments and within each department he can work with multiple groups. In each group he works on multiple projects. All the...
8
1859
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 need to build multiple mixed mode dll's used by a consumer application, do I have to implement multiple ManagedWrapper's (each embedded in indiviudal DLL project) and call all of them in my consumer application?
0
273
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: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appsettings> <add key = "ConnectionString" value =
0
1918
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 list. I want the list to highlight the multiple chosen values. here is part of the code. $dresscat = specdresscat($dresstypeid); //this is the query to get the values in the detail table $drcatrow = pg_fetch_array($dresscat);// the array for the...
0
861
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 like this '4/1/2007' ,i don't figure it out where i go wrong my code is : conn3.ConnectionString = myConnString conn3.Open() comanda.Connection = conn3 Dim sqlQueryCommand As New MySqlCommand("select * from " & table & " ;", conn3) Dim DR As...
0
2891
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 in my code below, I created the connection, connection string, etc and I opened the connection, executed the reader and then called the datareader.read() before any variable assignment below. I keep getting that error and I don't know why! I am...
0
9973
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11547
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7399
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.