从GridView值更新 [英] Update from GridView Values

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

问题描述

亲爱的朋友们,



我更新了gridview值..我给出了来自db的网格值的模块代码。但我在gridview中另外有一行更新..但最后我选择了wt行。这些值更新了数据库中的所有行..



我的更新代码是:





Dear Frnds,

I update gridview values.. i give module code that values comes to grid from db. but i additionally one row update in that gridview.. but finally wt row i choosed. that values are updated all rows in the DB..

my update code is:


if (chkBx.Checked == true)
{
    SqlCommand cmd1 = new SqlCommand("update Usr_Dtl set UsrId=@UsrId,ScreenCode=@ScreenCode,ScreenName=@ScreenName,UsrAccess=@UsrAccess,Delflg=@Delflg where UsrId = '" + TextBox1.Text + "'", con);

    cmd1.Parameters.AddWithValue("@UsrId", TextBox1.Text);
    cmd1.Parameters.AddWithValue("@ScreenCode", GridView1.Rows[i].Cells[0].Text);
    cmd1.Parameters.AddWithValue("@ScreenName", GridView1.Rows[i].Cells[1].Text);
    cmd1.Parameters.AddWithValue("@UsrAccess", 'Y');
    cmd1.Parameters.AddWithValue("@Delflg", 'N');
                       
    cmd1.ExecuteNonQuery();
}

推荐答案

从您的解释中不清楚。但我可以在代码中看到一个问题。

Not clear from your explanation. But I can see one problem in the code.
cmd1.Parameters.AddWithValue("@UsrId", TextBox1.Text);



这意味着它需要一个参数 @UserId 在查询中,但您没有在下面的命令中提到该参数。


That means it expects one Parameter @UserId in the query, but you have not mentioned that parameter in the below Command.

SqlCommand cmd1 = new SqlCommand("update Usr_Dtl set UsrId=@UsrId,ScreenCode=@ScreenCode,ScreenName=@ScreenName,UsrAccess=@UsrAccess,Delflg=@Delflg where UsrId = '" + TextBox1.Text + "'", con);



因此,将命令更改为...


So, change the Command to...

SqlCommand cmd1 = new SqlCommand("update Usr_Dtl set UsrId=@UsrId,ScreenCode=@ScreenCode,ScreenName=@ScreenName,UsrAccess=@UsrAccess,Delflg=@Delflg where UsrId = @UsrId", con);





另外,我建议您调试并查看在替换Command中参数的所有值后,它所做的动态查询是什么。确保它是正确的。



Also, I would suggest you to debug and see what is the dynamic query it makes after replacing all values for the parameters in the Command. Make sure that is correct.


通过调试代码检查网格行索引并清楚地解释问题
Check your grid row index by debugging the code and clearly explain the problem


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

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