【发布时间】:2008-10-10 08:08:39
【问题描述】:
替换问题:Update multiple rows into SQL table
这是用于更新考试结果集的代码片段。 数据库结构是给定的,但我可以提交存储过程以供包含(修改起来很痛苦,所以我把它保存到最后。)
问题:有没有更好的方法使用 SQL server v 2005.,net 2.0 ?
string update = @"UPDATE dbo.STUDENTAnswers
SET ANSWER=@answer
WHERE StudentID =@ID and QuestionNum =@qnum";
SqlCommand updateCommand = new SqlCommand( update, conn );
conn.Open();
string uid = Session["uid"].ToString();
for (int i= tempStart; i <= tempEnd; i++)
{
updateCommand.Parameters.Clear();
updateCommand.Parameters.AddWithValue("@ID",uid);
updateCommand.Parameters.AddWithValue("@qnum",i);
updateCommand.Parameters.AddWithValue("@answer", Request.Form[i.ToString()]);
try
{
updateCommand.ExecuteNonQuery();
}
catch { }
}
【问题讨论】:
标签: c# .net sql-server