我正在尝试在 switch case 语句中使用和更新命令,但是当我运行它时,它根本没有更新,不确定我在这里做错了什么。这是我的代码:
protected void update()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString);
SqlCommand Mycmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter("SELECT ID, Name, Stage from Mytable WHERE ID= @ID ", con);
DataTable dt = new DataTable();
da.SelectCommand.Parameters.AddWithValue("@ID", (ID));
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
switch (Convert.ToString(row["Stage"]))
{
case "1":
string myStage= txtStageLevel.Text;
Mycmd.CommandText = "UPDATE Mytable SET Stage=@myStage";
break;
}