本文介绍了如何更新asp.net中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出的代码不起作用.Table(AddedItem)未更新

Given code is not working.Table(AddedItem) is not uppdated

protected void Button1_Click(object sender, EventArgs e)
        {
            int st = 0,st1=0;
            if (IsPostBack)
            {
                try
                {
                    con.Open();
                   
                    st = Convert.ToInt32(TextBox1.Text);
                    SqlCommand cmd2 = new SqlCommand("SELECT Quantity FROM AddedItem where Item_Name='" + DropDownList3.SelectedItem.Text + "'", con);
                    SqlDataReader dr = cmd2.ExecuteReader(CommandBehavior.SingleRow);
                    if (dr.Read())
                    {

                        st1 = Convert.ToInt32(dr.GetValue(0).ToString());
                        dr.Close();
                    }
                    st1 = st1 - st;
                    SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity=st1", con);
                    cmd1.ExecuteNonQuery();
                   
                   
                }
                catch (SqlException ex)
                {

                }
                finally
                {
                    con.Close();

                }

}
}

}
}

推荐答案

st1 = st1 - st;
                    SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity=st1", con);









Write

st1 = st1 - st;
                    SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity="+st1, con);


SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity = " + st1, con);



添加了预标记



added pre tags


SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity=st1", con);



但这应该是



But it should be

SqlCommand cmd1 = new SqlCommand("UPDATE AddedItem SET Quantity="+st1, con);



希望这会有所帮助

添加了预标签并删除了多余的换行符



Hope this helps

added pre tags and removed superfluous line breaks


这篇关于如何更新asp.net中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 06:01