MySQL Read Problem

08/31/2010 11:31 -Fáng-#1
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:
[Only registered and activated users can see links. Click Here To Register...]

This is the error in the console:
[Only registered and activated users can see links. Click Here To Register...]

Attempting to figure out what's wrong:
[Only registered and activated users can see links. Click Here To Register...]

Any suggestions?
I am using MySqlHandler.dll
08/31/2010 11:33 .Lolcat#2
when i know that you must write (r.Read ()) you forgot the space
08/31/2010 11:48 -Fáng-#3
Quote:
Originally Posted by .Lolcat View Post
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 dowhatuwant#4
You could post the exception it throws in c#?
08/31/2010 13:12 Arcо#5
Don't you need to convert it to an int when reading it?
08/31/2010 13:25 ~Falcon#6
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 Korvacs#7
Quote:
Originally Posted by ~Falcon View Post
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 -Fáng-#8
Quote:
Originally Posted by ☆★Zuper★☆ View Post
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 View Post
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:

[Only registered and activated users can see links. Click Here To Register...]

Quote:
Originally Posted by ~Falcon View Post
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 View Post
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 _tao4229_#9
Where does it assign the connection the the database? :confused:
09/01/2010 01:13 bone-you#10
Quote:
Originally Posted by .Lolcat View Post
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 ImmuneOne#11
Quote:
Originally Posted by _tao4229_ View Post
Where does it assign the connection the the database? :confused:
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 -Fáng-#12
Quote:
Originally Posted by _tao4229_ View Post
Where does it assign the connection the the database? :confused:
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 ImmuneOne#13
Quote:
Originally Posted by -Fáng- View Post
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 -Fáng-#14
Quote:
Originally Posted by ImmuneOne View Post
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 VisualNaff#15
Thanks!!