Probleme d'ajout d'une ligne dans une table
je veut a jouter une ligne dans une table avec le paramètre insert mais ça me donne cette erreur ("Modifications non effectuées: risque de doublons dans champs index, clé primaire ou relation interdisant les doublons") sous access j'ai essayer de rajouter une ligne et j'ai pas eu de problème
voici le code :
code pour la table :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
private void tableproduction_journaliere(object sender, EventArgs e)
{
if (datasetproduction.Tables["production_journaliere"] == null)
{
production_journaliere.SelectCommand = new OleDbCommand();
production_journaliere.SelectCommand.Connection = Connectionproduction;
production_journaliere.SelectCommand.CommandText = "SELECT production_journaliere.*, production_journaliere.qte_realisee FROM production_journaliere WHERE (((production_journaliere.date_production)=Date()) AND ((production_journaliere.num_poste)='" + labelpost.Text.ToString() + "') AND ((production_journaliere.cleproduit)='" + labelreference.Text.ToString() + "'));";
production_journaliere.SelectCommand.CommandType = CommandType.Text;
production_journaliere.InsertCommand = new OleDbCommand();
production_journaliere.InsertCommand.Connection = Connectionproduction;
production_journaliere.InsertCommand.CommandText = "INSERT INTO production_journaliere (date_production,num_poste,cleproduit) VALUES (:date_production,:num_poste,:cleproduit)";
production_journaliere.InsertCommand.CommandType = CommandType.Text;
production_journaliere.InsertCommand.Parameters.Add(":date_production", OleDbType.DBDate,8);
production_journaliere.InsertCommand.Parameters.Add(":num_poste", OleDbType.LongVarChar,15);
production_journaliere.InsertCommand.Parameters.Add(":cleproduit", OleDbType.LongVarChar, 15);
Connectionproduction.Open();
production_journaliere.Fill(datasetproduction, "production_journaliere");
Connectionproduction.Close();
bindingproduction_journaliere.DataSource = datasetproduction;
bindingproduction_journaliere.DataMember = "production_journaliere";
gridopd.DataSource = datasetproduction;
gridopd.DataMember = "production_journaliere";
}
else
{
datasetproduction.Tables["production_journaliere"].Clear();
production_journaliere.SelectCommand = new OleDbCommand();
production_journaliere.SelectCommand.Connection = Connectionproduction;
production_journaliere.SelectCommand.CommandText = "SELECT production_journaliere.*,production_journaliere.qte_realisee FROM production_journaliere WHERE (((production_journaliere.date_production)=Date()) AND ((production_journaliere.num_poste)='" + labelpost.Text.ToString() + "') AND ((production_journaliere.cleproduit)='" + labelreference.Text.ToString() + "'));";
production_journaliere.SelectCommand.CommandType = CommandType.Text;
production_journaliere.InsertCommand = new OleDbCommand();
production_journaliere.InsertCommand.Connection = Connectionproduction;
production_journaliere.InsertCommand.CommandText = "INSERT INTO production_journaliere (date_production,num_poste,cleproduit) VALUES (:date_production,:num_poste,:cleproduit)";
production_journaliere.InsertCommand.CommandType = CommandType.Text;
production_journaliere.InsertCommand.Parameters.Add(":date_production", OleDbType.DBDate);
production_journaliere.InsertCommand.Parameters.Add(":num_poste", OleDbType.LongVarChar, 15);
production_journaliere.InsertCommand.Parameters.Add(":cleproduit", OleDbType.LongVarChar, 15);
Connectionproduction.Open();
production_journaliere.Fill(datasetproduction, "production_journaliere");
Connectionproduction.Close();
bindingproduction_journaliere.DataSource = datasetproduction;
bindingproduction_journaliere.DataMember = "production_journaliere";
gridopd.DataSource = datasetproduction;
gridopd.DataMember = "production_journaliere";
}
} |
code pour l'ajout
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| tableproduction_journaliere(sender, e);
if (datasetproduction.Tables["production_journaliere"].Rows.Count == 0)
{
MessageBox.Show(datasetproduction.Tables["production_journaliere"].Rows.Count.ToString());
production_journaliere.InsertCommand.Parameters[":date_production"].Value = DateTime.Today;
production_journaliere.InsertCommand.Parameters[":num_poste"].Value = labelpost.Text;
production_journaliere.InsertCommand.Parameters[":cleproduit"].Value = labelreference.Text;
DataRow Row1 = datasetproduction.Tables["production_journaliere"].NewRow();
Row1["date_production"] = DateTime.Today;
Row1["num_poste"] = labelpost.Text;
Row1["cleproduit"] = labelreference.Text;
datasetproduction.Tables["production_journaliere"].Rows.Add(Row1);
production_planifier.Update(datasetproduction.Tables["production_journaliere"]);
} |
remarque :
1 - la table est vide
2- j'ai un champs auto incrément.
merci d'avance.