Hello friends,
well i have really very big problem . i m using mysql database and windows Application i just want to know that when i m inserting same student name on that time it would be give me Message like "the Student name is Already Exits".. is it possible or not if yes than let me know wht is the code for it...
thanks in Advance
Name Khan
Problem in duplicate Values in C#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Santhosh NRank #4,788 · 325 reputationPosted Jan 31, 2010, 11:09 PM EST
string connString = "SERVER=" + server + ";" +
"DATABASE=mydatabase;" +
"UID=testuser;" +
"PASSWORD=testpassword;";
MySqlConnection cnMySQL = new MySqlConnection(connString);
MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
MySqlDataReader reader;
cmdMySQL.CommandText = "select * from mycustomers where username = '" + txtUser.Text + "'";
cnMySQL.Open();
reader = cmdMySQL.ExecuteReader();
if (reader.Read())
{
//user exists and perform a validation message here
}
else
{
//user does not exist
}
cnMySQL.Close();
Naeem KhanRank #2,072 · 698 reputationPosted Feb 2, 2010, 2:59 AM EST
Still i m not understanding whats going on this code..... please tell me in easy way if you have any application or demo than let me know or try to send me i really need ur help...
thanks in Advance