Database !!

+1 Johann Rino · August 6, 2014
Guys anyone know how to prevent duplicate Email Address record in MySql ? 

Post a Reply

Replies

Oldest  Newest  Rating
0 Brandon Elliott · August 6, 2014
use Brano's suggestion and then if case sensitivity is an issue then just convert the email address to lowercase before storing it in the database and it will no longer be an issue
0 JOhaL jaTT · August 6, 2014
sorry mate did not see C# i was about PHP 
0 JOhaL jaTT · August 6, 2014
you are doing more than it needs 
0 Johann Rino · August 6, 2014
Sorry guys ..


Here's my code in inserting records to mysql ..



 try
                                {
                                    string myConn = "datasource=localhost;port=3306;username=root;password=texx";
                                    string Query = "insert into mydatabase.clientinfo (ID,FirstName,LastName,EmailAddress,Gender,Password,Birthday,Address) values('" + this.IDNumber + "','" + this.FirstNameTxtBx.Text + "','" + this.LastNameTxtBx.Text + "','" + this.EmailAddTxtBx.Text + "','" + this.GenderCB.SelectedItem + "','" + this.PasswordTxtBx.Text + "','" + this.Birthday + "','" + this.AddressTxtBx.Text + "') ;";
                                    MySqlConnection mySqlConnection = new MySqlConnection(myConn);
                                    MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
                                    mySqlDataAdapter.SelectCommand = new MySqlCommand(" select * mydatabase.clientinfo ;", mySqlConnection);
                                    MySqlCommandBuilder mySqlCommandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);
                                    mySqlConnection.Open();
                                    MySqlCommand mySqlCommand = new MySqlCommand(Query, mySqlConnection);
                                    MySqlDataReader mySqlDataReader;
                                    try
                                    {
                                        mySqlDataReader = mySqlCommand.ExecuteReader();
                                        while (mySqlDataReader.Read())
                                        {
                                       
                                        }
                                        
                                    }
                                    catch (Exception) { }

                                }
                                catch (Exception) { }


--------------------------------------
This is the code I created to prevent duplicate records in my database :

string constr = ConfigurationManager.ConnectionStrings["connstr"].ToString();
MySqlConnection con = new MySqlConnection(constr);
string sql1 = "SELECT COUNT (EmailAddress) FROM mydatabase WHERE EmailAddress = '" + EmailAddTxtBx.Text + "' ";
MySqlCommand cmd = new MySqlCommand(sql1, con);
con.Open();
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp >0)
{
//show error message
}


But it didn't work..  :(
0 JOhaL jaTT · August 6, 2014
yes mate i know , how to prevent duplicate Email Address record in MySql.
  • 1

C#

107,092 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators