Register for your free account! | Forgot your password?

Go Back   elitepvpers > Conquer Online 2 > CO2 PServer - Discussions / Questions
You last visited: Today at 10:00

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

 

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

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
[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   #2
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 490
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   #3
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
I did, but the $check2 part is hard to translate to C#..
Basser is offline  
Thanks
1 User
Old   #4
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,159
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   #5
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
Thanks a lot, testing this now.
I'll edit this.

Edit:

Didn't work.
Basser is offline  
Thanks
1 User
Old   #6
 
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   #7
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
#request close

bisiol solved the problem.
Thnx a lot.
Basser is offline  
Thanks
1 User
Old   #8
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 490
Nice bisol
PeTe Ninja is offline  
Thanks
1 User
Old   #9
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 992
#Closed


tanelipe is offline  
Thanks
1 User
Closed Thread



« Previous Thread | Next Thread »

Similar Threads
MySQL Command Line
Wie komm ich dahin ?
1 Replies - Metin2 PServer - Discussions / Questions
MySQL Navicat 1130-Host'5.xxx.xx.xxx' is not allowed to connect to the MySQL Server
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...
14 Replies - Metin2 PServer - Discussions / Questions
[Release] MySQL Insert system
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...
18 Replies - CO2 PServer Guides & Releases
Where is the mysql command client?
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!...
7 Replies - EO PServer Hosting



All times are GMT +1. The time now is 10:00.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2017 elitepvpers All Rights Reserved.