即使没有显示错误,如何处理行更新事件 [英] How to handle row-updating event even-though no error shown

查看:55
本文介绍了即使没有显示错误,如何处理行更新事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Rowupdate事件使用存储过程更新表。在执行时显示错误但是在给出更新值时没有更改表值。当我们给出值并单击更新按钮时,文本框中没有值更改且没有出现错误,它将保留为上一个表单。



我尝试过的内容:



protected void GridView1_RowUpdating(object sender,GridViewUpdateEventArgs e)

{

Label contactid = GridView1.Rows [e。 RowIndex] .FindControl(lbl_id)作为标签;

TextBox name = GridView1.Rows [e.RowIndex] .FindControl(TextBox1)as TextBox;

TextBox gender = GridView1.Rows [e.RowIndex] .FindControl(TextBox2)as TextBox;

con.Open();



SqlCommand cmd = new SqlCommand(updatetbales,con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(@ contactid,SqlDbType.Int).Value =(int.Parse(contactid.Text));

cmd.Parameters.Add(@ name,SqlDbType .VarChar,50)。Value = name.Text.ToString();

cmd.Parameters.Add(@ gender,SqlDbType.VarChar,50).Value = gender.Text.ToString( );



cmd.ExecuteNonQuery();



con.Close();

GridView1.EditIndex = -1;

grid();

}

Tried to update a table using Rowupdate event using stored procedure.no error shown at the time of execution but while giving the values for updation no changes in the of table value.when we give the value and click on update button there is no value change in the text box and no error shooted ,it will remain as the previous form.

What I have tried:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label contactid = GridView1.Rows[e.RowIndex].FindControl("lbl_id") as Label;
TextBox name = GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
TextBox gender = GridView1.Rows[e.RowIndex].FindControl("TextBox2") as TextBox;
con.Open();

SqlCommand cmd = new SqlCommand("updatetbales", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@contactid", SqlDbType.Int).Value = (int.Parse(contactid.Text));
cmd.Parameters.Add("@name", SqlDbType.VarChar,50).Value = name.Text.ToString();
cmd.Parameters.Add("@gender", SqlDbType.VarChar, 50).Value = gender.Text.ToString();

cmd.ExecuteNonQuery();

con.Close();
GridView1.EditIndex = -1;
grid();
}

推荐答案

什么是从 cmd.ExecuteNonQuery()返回的值?你知道这会返回一个INT,反映更新的记录数量;类似于SSMS中返回的行受影响的值。



如果直接在SQL Server上执行此过程会怎样?



grid()方法有什么作用?



是的,我没有回答你的问题。我所做的就是让你思考你发布的内容以及其他人帮助你的内容。当你回答这些问题时,它可能对你有帮助。
What is the value being returned from cmd.ExecuteNonQuery()? You do know this returns an INT reflecting the amount of records updated; analogous to the rows affected value returned in SSMS.

What happens if you execute this procedure directly on the SQL Server?

What does the grid() method do?

Yes, I have not answered your question. What I have done is make you think about what you have posted and what would be helpful for others to help you out. Maybe it helps you as you answer these questions.


向后工作。你有多个可能的失败点。



从一个简单的SELECT COUNT(*)FROM ...开始测试连接。

然后使用CONSTANTS(不是文本框)进行参数化查询。

然后文本框等
Work backwards. You have multiple possible points of failure.

Start with a plain "SELECT COUNT(*) FROM ..." which tests the connection.
Then a parameterized query using CONSTANTS (not text boxes).
Then text boxes, etc.


MadMyche

谢谢你的回复?我认为返回值是受命令影响的行数。
MadMyche
Thank you for your reply?i think the return value is the number of rows affected by the command.


这篇关于即使没有显示错误,如何处理行更新事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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