Mfwamba Tshimanga

Mfwamba Tshimanga

  • NA
  • 155
  • 46.2k

Repeated record...

May 10 2014 11:37 AM
Hi!
 
I have a question. I am sure that is possible in Csharp.
How can I with my codes dont allow repeated record (for instance, I dont want see repeated "code" in my database). Need help on it please
I never do it. Want to learn how to do. Thanx!

private void btnSave_Click_1(object sender, EventArgs e)

{

{

conn = new SqlConnection(connstr);

comm = new SqlCommand();

conn.Open();

SqlParameter code = new SqlParameter("@code", SqlDbType.NChar);

comm.Parameters.Add(code);

code.Value = mycode.Text;

comm.Connection = conn;

comm.CommandText = "insert into classenumer values(@code)";

try

{

comm.ExecuteNonQuery();

MessageBox.Show("Good saving!");

mycode.Clear();

}

catch (Exception)

{

MessageBox.Show("Sorry, not saved");

}

finally

{

conn.Close();

}

}

} 

Answers (9)