如何更新gridview中的选定行? [英] How to update selected row in gridview?

查看:100
本文介绍了如何更新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);

       }
   }

推荐答案

我想你错过了以下行代码:



I think you have missed below line of code :

cmd.ExecuteNonQuery();





:)



:)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆