I wrote this codes for saving my records. But I dont want to see later my records repeated (or duplicated). How can I do to prevent it. When the same datas is already exist its should inform and refus. Save only when its doesnt exist in the database:
...
public Form1()
{
InitializeComponent();
}
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WindowsFormsApplication1\App_data\test.mdb;Persist Security Info=False");
OleDbCommand comm;
string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WindowsFormsApplication1\App_data\test.mdb;Persist Security Info=False";
private void button1_Click(object sender, EventArgs e)
{
conn = new OleDbConnection(connstr);
comm = new OleDbCommand();
conn.Open();
OleDbParameter name = new OleDbParameter("@name", SqlDbType.Date);
OleDbParameter fonction = new OleDbParameter("@fonction", SqlDbType.Date);
comm.Parameters.Add(name);
comm.Parameters.Add(fonction);
name.Value = textBox1.Text;
fonction.Value = textBox2.Text;
comm.Connection = conn;
comm.CommandText = "select count(*) from Not_duplicated_datas where name = @name";
int count = (int)comm.ExecuteScalar();
comm.ExecuteNonQuery();
conn.Close();
}