Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 10:01:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: A bit of help C# and MySql  (Read 3417 times)

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
A bit of help C# and MySql
« on: August 19, 2011, 07:09:59 AM »
Hey guys, dont know if this is the right place but I will post here anyway...

I am writing a program and I am having some issues with selecting the MySql data using C#.

Quote
private void Checks()
        {
            string UN = Username_Text.Text;
            string Pass = Password_Text.Text;

            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);

            try
            {

                cmd.Select("users").Where("Username", UN);
                MySqlReader r = new MySqlReader(cmd);

                while (r.Read()) // Breakpoint added here shows that the program is reading up to this point but does not read anything below this line until the return;
                {
                    string RealPassword = r.ReadString("Password");
                    string RealUsername = r.ReadString("Username");
                    if (RealUsername == UN && RealPassword == Pass)
                    {
                        MessageBox.Show("YAY!");
                    }
                    else
                    {
                        MessageBox.Show("DAMN!");
                    }
                }
                return;
            }
            catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }
        }

Anyone can help me with this? Its a simple login script but I just cant get my head around it and need a fresh pair of eyes

Thanks in advance

.Beatz

My MySql DLL is attached
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #1 on: August 19, 2011, 08:25:51 AM »
Where is your MySQL Dll from?  Is it yours, or did you get it from somewhere?  If you got it from somewhere, I'd suggest placing a link to where.  If it's yours, I'd suggest posting source instead. 

Why?

Well, not to be a cynic, but you have one post.  I'm not going to download anything I'm not totally sure of from someone with one post.  Sorry, but that's a sign of the internet times.

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #2 on: August 19, 2011, 08:33:01 AM »
downloaded from Elitepvpers.de... It come in a source that I was working on and can't find the source code for it or the download link...

I  know I only have one post but I can assure you that the DLL is what I say it is... a dll nothing else nothing more.

I will keep looking for the download I got it from and will post it if I can find it...
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

Stephen66515

  • Animated Giffer in Chief
  • Honorary Member
  • Joined in 2010
  • **
  • Posts: 3,129
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #3 on: August 19, 2011, 09:39:07 AM »
I will back Beatz up on this as I do know him.

I _tried_ to help on this subject but I kinda failed lol

*edit*

Downloaded the rar file and uploaded it to my post, its legit :) (Couldnt upload as a direct .dll so had to re-rar it lol)

If you wanna download it DIRECTLY as ONLY a .dll, then use this link:

http://86.28.143.246/MySqlHandler.dll (MY Web Server)
« Last Edit: August 19, 2011, 09:55:33 AM by Stephen66515 »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #4 on: August 19, 2011, 11:55:53 AM »
What errors are you getting, and what is the structure of the table you're querying?

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #5 on: August 19, 2011, 08:21:11 PM »
I am not getting any errors it just wont read anything from the database... so far I have Username and Password fields in the MySql database I have tried using a connection string instead of this dll but failed miserably while trying to select Username as row and get the password from the same row...

Sorry for the erratic way I have written stuff I am not very good at explaining things lol (just ask Stephen)
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #6 on: August 20, 2011, 12:07:49 AM »
Is the database you connecting to defined elsewhere?

Why is there no FROM {TABLE} reference in the code?

Granted I know nothing of this dll you're trying to use but this line just don't look right:
Code: C# [Select]
  1. cmd.Select("users").Where("Username", UN);

Shouldn't it be something more like:
Code: C# [Select]
  1. cmd.Select("Username, Password").From.("Users").Where("Username", UN);

Considering (I'm left guessing...) you're probably getting the DAMN! messagebox ... It's probably returning an empty results set, or a query syntax error that isn't being seen/checked for.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #7 on: August 20, 2011, 07:35:35 AM »
I'd agree with SJ on this one.  It appears like a syntax problem with the DLL you are using rather than a C# problem.  I tried to find a reference online to that DLL and maybe documentation and found something, but I can't download without registering.

It seems that there is source on that site that uses it in this thread.  I can't download it to see since I'm not registered, but I'd recommend downloading it and taking a look to see what the syntax should be from the source.

Also, if you're just trying to use MySQL and can't get this to work, you might look into MySQL Connector/NET.  There's a good tutorial on using it here.

 

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #8 on: August 20, 2011, 11:37:01 AM »
Also, if you're just trying to use MySQL and can't get this to work, you might look into MySQL Connector/NET.  There's a good tutorial on using it here.

I'll second that, I've used the MySQL supplied SKD for a couple of C++ projects. All of which worked out quite well.

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #9 on: August 20, 2011, 07:15:51 PM »
@Stoic Joker - I am defining the database when the program loads. Also I am not getting either MessageBox

I will try and use the MySql connector/NET and see if that helps at all :)

Will keep you up to date on how its going and if I need a hand

Cheers guys helped quite alot

*EDIT*

Found out the dll keeps a constant connection so the message boxes wouldn't show up.

Spoiler
public bool Checks()
        {
            MySqlConnection Conn = MySqlSettings.GetConnection(); Conn.Open();
            bool exist = false;
            string user = Username_Text.Text;
            string userpass = Password_Text.Text;

            try
            {
                lock (Conn)
                {
                    MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `users` WHERE Username='" + user + "' AND Password='" + userpass + "'", Conn);
                    MySqlDataReader DR = Cmd.ExecuteReader();
                    while (DR.Read())
                    {
                        string userpass1;
                        string user1;

                        userpass1 = (DR["Password"].ToString());
                        user1 = (DR["Username"].ToString());

                        if (user == user1 && userpass == userpass1)
                        {
                            exist = true;
                        }
                    }
                    DR.Close();
                }
                Conn.Close();
            }
            catch (Exception)
            {
                Conn.Close();
                return true;
            }
            if (exist == true)
            {
                MessageBox.Show("Logged in");
            }
            else
            {
                MessageBox.Show("Username or Password is wrong\nPlease try again");
            }

            return exist;
        }


Now it works like a dream as long as I don't use the dll

Cheers for the help guys
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka
« Last Edit: August 20, 2011, 10:10:58 PM by .Beatz, Reason: Problem solved »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,780
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #10 on: August 21, 2011, 09:20:12 AM »
if (exist == true)
Why do you code double comparisons? 'exist' is a boolean already, so it's either true or false, writing 'if (exist)' is sufficient.

.Beatz

  • Member
  • Joined in 2011
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: A bit of help C# and MySql
« Reply #11 on: August 22, 2011, 10:57:28 AM »
I do that when I am working on some things to help me look around and see stuff easier :)
“Invention, my dear friends, is 93% perspiration, 6% electricity, 4% evaporation, and 2% butterscotch ripple.” – Willy Wonka
« Last Edit: August 22, 2011, 01:00:41 PM by .Beatz »