Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 14:44

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[HELP]C# MySQL Command insert if not exsist?

Discussion on [HELP]C# MySQL Command insert if not exsist? within the CO2 Private Server forum part of the Conquer Online 2 category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
[HELP]C# MySQL Command insert if not exsist?

Code:
MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + fillBox.Text + "','3')", Connection);
Now, I want it to check if the value of fillBox.Text doesn't excist before making the account, so It wont create the same account. I tried making it in a try, that didn't help, it just make several accounts with the same name.

~Bas
Basser is offline  
Thanks
1 User
Old 09/03/2009, 19:59   #2
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
Umm.. I dont know if this will help, check out the register page?

I did this before but i dont remember how... I made a fully working accoun register form, i dont have it anymore though sorry.
PeTe Ninja is offline  
Thanks
1 User
Old 09/03/2009, 20:21   #3
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
I did, but the $check2 part is hard to translate to C#..
Basser is offline  
Thanks
1 User
Old 09/03/2009, 20:37   #4
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,162
Here's a crappy way of doing it:


Quote:
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `accounts` WHERE `AccountID` = "'" + fillBox.Text + "'", Connection);
MySqlDataReader rdr = cmd.ExecuteReader();
bool exist = false;
if (rdr.Read())
exist = true;

if (!exist)
{
Your code goes here.
}
_Emme_ is offline  
Thanks
1 User
Old 09/03/2009, 20:38   #5
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
Thanks a lot, testing this now.
I'll edit this.

Edit:

Didn't work.
Basser is offline  
Thanks
1 User
Old 09/03/2009, 20:52   #6
 
bisiol's Avatar
 
elite*gold: 0
Join Date: Aug 2005
Posts: 44
Received Thanks: 69
Code:
        private bool Check(string acc)
        {
            bool exists = false;
            MySqlCommand Command = new MySqlCommand("SELECT * FROM `accounts` WHERE `AccountID` = \"" + acc + "\"", Connection);
            MySqlDataReader DR = Command.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                if (Convert.ToString(DR["AccountID"]) == acc)
                    exists = true;
            }
            DR.Close();
            Command.Dispose();
            return exists;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string acc = fillBox.Text;
            if (acc != "")
                if (!Check(acc))
                {
                    MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + acc + "','3')", Connection);
                    Command.ExecuteNonQuery();
                    Command.Connection.Close();
                    Command.Connection.Dispose();
                    Command.Dispose();
                    MessageBox.Show("AccountID created");
                }
                else
                {
                    MessageBox.Show("AccountID already taken");
                }
        }
I hope it helps.
bisiol is offline  
Thanks
2 Users
Old 09/03/2009, 20:56   #7
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
#request close

bisiol solved the problem.
Thnx a lot.
Basser is offline  
Thanks
1 User
Old 09/03/2009, 22:00   #8
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
Nice bisol
PeTe Ninja is offline  
Thanks
1 User
Old 09/04/2009, 00:11   #9
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
#Closed
tanelipe is offline  
Thanks
1 User
Closed Thread


Similar Threads Similar Threads
MySQL Command Line
01/05/2011 - Metin2 Private Server - 1 Replies
Wie komm ich dahin ?
MySQL Navicat 1130-Host'5.xxx.xx.xxx' is not allowed to connect to the MySQL Server
08/07/2010 - Metin2 Private Server - 14 Replies
Hallo com, ich habe ein Problem mit Navicat. Undzwar habe ich diesen Fehler hier : "1130-Host'5.xxx.xx.xxx' is not allowed to connect to the MySQL Server" seid gestern. Ich dachte mir mal ich änder mein Navicat Passwort um... Als ich dies getan habe, und meinen Server rebootet habe und Navicat neugestartet habe, und ich mich wieder in Navicat einloggen wollte kam diese Fehlermeldung. Nun habe ich das Problem das ich mich nicht mehr mit Navicat connecten kann. Habe schon alles versucht...
[Release] MySQL Insert system
07/18/2010 - CO2 PServer Guides & Releases - 18 Replies
Ello! First of all, this is NOT sourcedependent, which means you can use this on any source without modifying the code. This is an replacement for all of you who still uses normal MySQL queries. Use this code to clean up, make it easier and more orginazed. Here's how it looks: Example: (Original (LOTF for example))
Where is the mysql command client?
12/02/2008 - EO PServer Hosting - 7 Replies
In the intructions (#23) on the "All Things Guide" it says to put this command in the mysql command client. What exactly do i put in, and where! Please help! -Nicolexo



All times are GMT +1. The time now is 14:45.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.