|
You last visited: Today at 10:46
Advertisement
MySQL Read Problem
Discussion on MySQL Read Problem within the CO2 Private Server forum part of the Conquer Online 2 category.
08/31/2010, 11:31
|
#1
|
elite*gold: 0
Join Date: Jul 2010
Posts: 223
Received Thanks: 23
|
MySQL Read Problem
Hey Everyone!
I can't really figure out what's wrong with this code:
Code:
public static bool CharExists(string Name)
{
bool exists = false;
MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
cmd.Select("cq_user").Where("name", Name);
MySqlReader r = new MySqlReader(cmd);
[COLOR="Red"] if (r.Read())[/COLOR] [COLOR="SeaGreen"]// Line 79[/COLOR]
{
if (r.ReadInt32("id") > 0)
exists = true;
}
return exists;
}
Basically, this is used in the creation of a new character.
This is how it looks from the database:
This is the error in the console:
Attempting to figure out what's wrong:
Any suggestions?
I am using MySqlHandler.dll
|
|
|
08/31/2010, 11:33
|
#2
|
elite*gold: 100
Join Date: Dec 2009
Posts: 3,504
Received Thanks: 1,219
|
when i know that you must write (r.Read ()) you forgot the space
|
|
|
08/31/2010, 11:48
|
#3
|
elite*gold: 0
Join Date: Jul 2010
Posts: 223
Received Thanks: 23
|
Quote:
Originally Posted by .Lolcat
when i know that you must write (r.Read ()) you forgot the space
|
x_x" ... that's not the problem. lol
That doesn't really make sense... but i tried it anyways. Didn't work still. Line 79.
Thanks for trying =\
I'm going to sleep- I'll respond in the morning.
|
|
|
08/31/2010, 13:02
|
#4
|
elite*gold: 0
Join Date: Aug 2010
Posts: 452
Received Thanks: 75
|
You could post the exception it throws in c#?
|
|
|
08/31/2010, 13:12
|
#5
|
elite*gold: 0
Join Date: Oct 2009
Posts: 8,783
Received Thanks: 5,304
|
Don't you need to convert it to an int when reading it?
|
|
|
08/31/2010, 13:25
|
#6
|
elite*gold: 0
Join Date: Nov 2009
Posts: 129
Received Thanks: 45
|
I've never heard of or used MySqlReader, it's always been MySqlDataReader afaik.
Even then, to initialize you call MySqlCommand.ExecuteReader();
|
|
|
08/31/2010, 17:00
|
#7
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
|
Quote:
Originally Posted by ~Falcon
I've never heard of or used MySqlReader, it's always been MySqlDataReader afaik.
Even then, to initialize you call MySqlCommand.ExecuteReader();
|
Indeed, you need to use MySqlDataReader:
Code:
MySqlDataReader Reader = Com.ExecuteReader();
while (Reader.Read())
{
//Do Work
}
I would guess that MySqlReader (even though i could find 0 documentation on it on the net, which makes me doubt its existance o.O) would be a class which you would inherit from if you wanted to do really really custom retreives. Although like i said i couldnt find anything even referencing it.
|
|
|
08/31/2010, 18:23
|
#8
|
elite*gold: 0
Join Date: Jul 2010
Posts: 223
Received Thanks: 23
|
Quote:
Originally Posted by ☆★Zuper★☆
You could post the exception it throws in c#?
|
It's posted on the main post in that picture. I boxed the line in red. That's the exception that it prints.
Quote:
Originally Posted by .Arco
Don't you need to convert it to an int when reading it?
|
Well, the problem is with line 79, not line 81. If I remove line 81, it comes up with the same error on line 79:
Quote:
Originally Posted by ~Falcon
I've never heard of or used MySqlReader, it's always been MySqlDataReader afaik.
Even then, to initialize you call MySqlCommand.ExecuteReader();
|
I looked it up... it's a bit more complicated like that.
Quote:
Originally Posted by Korvacs
Indeed, you need to use MySqlDataReader:
Code:
MySqlDataReader Reader = Com.ExecuteReader();
while (Reader.Read())
{
//Do Work
}
I would guess that MySqlReader (even though i could find 0 documentation on it on the net, which makes me doubt its existance o.O) would be a class which you would inherit from if you wanted to do really really custom retreives. Although like i said i couldnt find anything even referencing it.
|
The thing is... this code works perfectly in my other source!
That's what I don't get. I tried it your way but it won't work either. Same Error. I think ImmuneOne wrote a Command using the DataReader. I just found it. Lets see if it works...
Well ****. ImmuneOne's code works perfectly! Maybe it was the database type since it's a binary database. Weird! Well thanks for trying to help everyone. I appreciate it!
Working Code:
Code:
public static bool CharExists(string Name)
{
bool exists = false;
MysqlCommand Cmd = new MysqlCommand(CommandType.SELECT);
Cmd.Select("*", "cq_user");
Cmd.Done();
while (Cmd.DataReader.Read())
{
if ((Cmd.Read("name") == Name))
if (Convert.ToUInt32(Cmd.Read("id")) > 0)
exists = true;
}
Cmd.End();
return exists;
}
|
|
|
08/31/2010, 18:38
|
#9
|
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
|
Where does it assign the connection the the database?
|
|
|
09/01/2010, 01:13
|
#10
|
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
|
Quote:
Originally Posted by .Lolcat
when i know that you must write (r.Read ()) you forgot the space
|
Since when do you put spaces between a function and the parenthesis?
Working code:
Code:
while (Cmd.DataReader.Read())
Not working code:
Code:
if (r.Read()) // Line 79
r = Reader, DataReader = DataReader. Please use the same class before you say they don't work the same.
Different classes do different things and have different ways to handle things. That is why they are not the same class.
|
|
|
09/01/2010, 02:08
|
#11
|
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
|
Quote:
Originally Posted by _tao4229_
Where does it assign the connection the the database? 
|
Everytime the connection accessor gets called within the custom ExecuteCmd() function, the accessor checks if the connection is broken/closed, if so, it get's re-initialized.
|
|
|
09/01/2010, 02:24
|
#12
|
elite*gold: 0
Join Date: Jul 2010
Posts: 223
Received Thanks: 23
|
Quote:
Originally Posted by _tao4229_
Where does it assign the connection the the database? 
|
You're completely right! That's not right at all! It's correct but it doesn't actually work! =o lol
This is the code I finally came up with:
Code:
int CharID = 0;
MySqlDataReader Reader;
MySqlCommand Cmd = new MySqlCommand("SELECT * FROM cq_user WHERE account='" + Account + "'", connection);
Reader = Cmd.ExecuteReader();
while (Reader.Read())
{
if (Reader.GetString("account") == Account)
CharID = Reader.GetInt32("id");
}
connection.Close();
Thread.Sleep(200);
(Opens the connection and sets the connection earlier up in the project) =]
|
|
|
09/01/2010, 07:10
|
#13
|
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
|
Quote:
Originally Posted by -Fáng-
You're completely right! That's not right at all! It's correct but it doesn't actually work! =o lol
This is the code I finally came up with:
Code:
int CharID = 0;
MySqlDataReader Reader;
MySqlCommand Cmd = new MySqlCommand("SELECT * FROM cq_user WHERE account='" + Account + "'", connection);
Reader = Cmd.ExecuteReader();
while (Reader.Read())
{
if (Reader.GetString("account") == Account)
CharID = Reader.GetInt32("id");
}
connection.Close();
Thread.Sleep(200);
(Opens the connection and sets the connection earlier up in the project) =]
|
Code:
MysqlCommand Cmd = new MysqlCommand(CommandType.SELECT);//CmdType for the constructor//Adds Select <V> from <T>
Cmd.Select("*", "cq_task");//Replaces <V> with * and <T> cq_task
Cmd.Done();//Executes cmd
while (Cmd.DataReader.Read())//While datareader reads
{
}
Cmd.End(); //Close connection
|
|
|
09/01/2010, 07:36
|
#14
|
elite*gold: 0
Join Date: Jul 2010
Posts: 223
Received Thanks: 23
|
Quote:
Originally Posted by ImmuneOne
Code:
MysqlCommand Cmd = new MysqlCommand(CommandType.SELECT);//CmdType for the constructor//Adds Select <V> from <T>
Cmd.Select("*", "cq_task");//Replaces <V> with * and <T> cq_task
Cmd.Done();//Executes cmd
while (Cmd.DataReader.Read())//While datareader reads
{
}
Cmd.End(); //Close connection
|
I tried that but it doesn't read what I want it to read. The one I'm using is more precise. Thanks for helping out though! =P Your base is great.
|
|
|
09/01/2010, 23:43
|
#15
|
elite*gold: 0
Join Date: Sep 2010
Posts: 41
Received Thanks: 1
|
Thanks!!
|
|
|
 |
|
Similar Threads
|
[READ]MySQL Codequalität
06/08/2010 - Metin2 Private Server - 0 Replies
Reasoning, der führende Anbieter der "automatischen Softwarekontrolle" (ASI) kommt im Rahmen einer Studie zu dem Ergebnis, daß die Codequalität von MySQL höher liegt als bei kommerziellen Datenbanken.
Insbesondere stellte Reasoning fest, daß:
|
[READ]MySQL erneuerte Server Leisung [Release]
06/07/2010 - Metin2 Private Server - 8 Replies
Hallo
die MySQL AG hatt neue leistung. MySQL läuft nun um 30% schneller
bitte seht euch die anhänge an.
mfg MySQL Support.
bitte öffnen die detai MySQL
dann akutualisiert euer Server
|
Problem with MySql
11/21/2009 - CO2 Private Server - 13 Replies
Hi guys i found a Conquer 1.0 Source from 4botters
And i keep getting this error
If you can help pleas reply =)
|
Problem mit MySQL
10/22/2009 - Flyff Private Server - 22 Replies
Ich hab folgendes Problem mit MySQL.
Ich kann den Service nicht starten.
Wenn ich MySQL Server Instance Configuration mache und alles so mache wie in dem PServer Guide beschrieben und dann auf Execute klicke kommt bei "Prepare configuration" und "Write configuration file" ein Haken und bei "Start Service" kommt dan ein Kreuz. Unten steht dann:
"Could not start the service MySQL. Error: 0"
Ich hoffe ihr könnt mir mal wieder helfen ;-)
|
[help]mysql problem
06/13/2009 - CO2 Private Server - 2 Replies
everytime i try to set up mysql when i come to the configs it wont start the server after i have finished the configs anyone know wats going on
|
All times are GMT +1. The time now is 10:48.
|
|