|
You last visited: Today at 14:44
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.
09/03/2009, 11:54
|
#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
|
|
|
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.
|
|
|
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#..
|
|
|
09/03/2009, 20:37
|
#4
|
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.
}
|
|
|
|
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.
|
|
|
09/03/2009, 20:52
|
#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.
|
|
|
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.
|
|
|
09/03/2009, 22:00
|
#8
|
elite*gold: 0
Join Date: Jan 2009
Posts: 1,922
Received Thanks: 491
|
Nice bisol
|
|
|
09/04/2009, 00:11
|
#9
|
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
|
#Closed
|
|
|
 |
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.
|
|