Je dois ouvrir une connexion à la base de données SQL et lire un sous-ensemble d'une table et soit mettre à jour un enregistrement si existe ou insérer si non trouvé. Ayant truoble mise à jourQuestion sur la mise à jour/insertion d'une datatable dans un ensemble de données
SqlConnection conn = new SqlConnection(ConnectionStrings.PgenIntranet.SqlClientConnectionString);
SqlDataAdapter indicators = new SqlDataAdapter();
string sql = "SELECT * FROM BusinessApplications.tbl_WPI_Site_Indicators where Year = '" + year +
"' and Month = '" + month + "' and PlantId = " + site.ID;
indicators.SelectCommand = new SqlCommand(sql, conn);
SqlCommandBuilder cb = new SqlCommandBuilder(indicators);
indicators.UpdateCommand = cb.GetUpdateCommand();
DataSet ds = new DataSet();
indicators.Fill(ds, "indtable");
DataTable indtable = ds.Tables["indtable"];
// this logic not working
if (indtable.Rows.Count == 0) { indtable.NewRow(); }
DataRow dr = indtable.NewRow();
/// not sure how to make this work
indtable[1]["PlantId"] = site.ID;
dr["PlantId"] = site.ID;
Je ne suis pas lié à cette vieille ADO, avez-vous une suggestion? – BillTetrault
@Bill NHibernate & Entity Framework sont deux ORM qui sont très populaires et ont eu beaucoup de publicité. Voir http://stackoverflow.com/questions/3251849/please-recommend-net-orm-for-n-tier-development –