0
問題是當我添加第二個datarow數據集。如果我刪除//意見,我只拿到1行補充,而不是80問題與SQLDataAdapter和更新
SqlDataAdapter indicatorsExp = new SqlDataAdapter();
string sqlExp = "SELECT * FROM BusinessApplications.tbl_WPI_Site_Indicators_Exp " +
"where Year = '" + year + "' and Month = '" + month + "'";
indicatorsExp.SelectCommand = new SqlCommand(sqlExp, conn);
SqlCommandBuilder cbexp = new SqlCommandBuilder(indicatorsExp);
indicatorsExp.InsertCommand = cbexp.GetInsertCommand();
DataSet dsExp = new DataSet();
indicatorsExp.Fill(dsExp, "explanations");
DataTable explanations = dsExp.Tables["explanations"];
//.......
foreach (ISite site in sites)
{
DataRow drexp1 = explanations.NewRow();
try
{
drexp1["PlantId"] = site.ID;
drexp1["Month"] = month;
drexp1["Year"] = year;
}
catch { }
DataRow drexp2 = explanations.NewRow();
try
{
drexp2["PlantId"] = site.ID;
drexp2["Month"] = month;
drexp2["Year"] = year;
}
catch { }
explanations.Rows.Add(drexp1);
indicatorsExp.Update(dsExp, "explanations");
// explanations.Rows.Add(drexp2);
// indicatorsExp.Update(dsExp, "explanations");
}
你可以讓我們在你想要在這裏玩魔術嗎?它看起來很混亂,我無法弄清楚你想要做什麼 – Jeroen 2010-08-04 17:27:28