需要您的帮助来更新代码 [英] need your help for updating code

查看:59
本文介绍了需要您的帮助来更新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码进行更新,我想用正确的代码更新数据网格中所选行的事件,此代码更改数据库中所有事件,但我想更改所选行、、、
请注意,datagridview仅显示事件coloumn

this code for update ,, i wante the right code yo update the event of just selected row from data grid,,, this code change all event from data base but i want to change the selected row ,,,
note ,, the datagridview show just event coloumn

for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
           {
              
             
                       con.Open();
                       SqlCommand cmd = new SqlCommand("update calender set event='" + dataGridView1.SelectedRows[i].Cells[0].Value +  "'", con);

                   cmd.ExecuteNonQuery();
                   con.Close();
               }

推荐答案

您可以在网格中分配Datakeynames并将其绑定到列ID....否则应隐藏一列,然后再次将其绑定到columnid并在where子句的sql查询中传递该columnid.

受保护的void grdQuestion_RowDeleting(对象发送者,GridViewDeleteEventArgs e)

{
int id =(int)grdQuestions.DataKeys [e.RowIndex] .Value;

}

希望对您有帮助
You can assign Datakeynames in grid and bind it to column id.... else have one column that should be invisible and again bind it to columnid and pass that columnid in your sql query in where clause.

protected void grdQuestion_RowDeleting(object sender, GridViewDeleteEventArgs e)

{
int id = (int)grdQuestions.DataKeys[e.RowIndex].Value;

}

Hope this helps


这篇关于需要您的帮助来更新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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