如何更新gridview中的选定行

如何更新gridview中的选定行

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

问题描述

0
down vote
favorite

I have a TextBox with id=txtPlace and a gridview. If a user selects a row an put some Information in the TextBox and click on save. The Information should replace older records in the database(SQL)







But It does not work. When I click on save, nothing happens.





我尝试过:





What I have tried:

protected void btnSave_Click(object sender, EventArgs e)
   {
       var id = GridView2.SelectedDataKey.Values[0].ToString();
       string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
       using (SqlConnection conn = new SqlConnection(constr))
       {

           string query = "UPDATE user SET place= @place where ID = @D ";
           SqlCommand cmd = new SqlCommand(query, conn);
           cmd.Parameters.AddWithValue("@place", txtPlace.Text);
           cmd.Parameters.AddWithValue("@ID", id);

       }
   }

推荐答案

cmd.ExecuteNonQuery();





:)



:)


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

08-23 21:00