调试后更新语句的异常. [英] exception for update statement after debuging.

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

问题描述


嗨.

我在Asp.net中用以下代码编写了一个更新状态:

Hi.

I have written an update statemnt in Asp.net with the code below:

protected void UpdateButton(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = ConfigurationManager.ConnectionStrings["PersonTest"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "UPDATE Person SET (Name=@Name,Family=@Family) where (PersonId=@PersonId)";
            cmd.Parameters.AddWithValue("@Name", textbox1.Text);
            cmd.Parameters.AddWithValue("@Family", TextBox2.Text);
            cmd.Parameters.AddWithValue("@PersonId", txtId.Text);

            cmd.Connection = conn;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }



但是在调试之后会发生此异常:
SqlException未由用户代码处理.
''(''附近的语法不正确.


是什么问题?



but after debuging this exception occures :
SqlException was unhandled by user code.
Incorrect syntax near ''(''.


what is the problem?

推荐答案

您能删除您的注释行并尝试下一次吗.........

并像
一样使用此代码 cmd.CommandText ="UPDATE Person SET Name = @ Name,Family = @ Family,其中PersonId = @ PersonId" ;;
Can u remove your commented line and try next time .........

and use this code as like
cmd.CommandText = "UPDATE Person SET Name=@Name,Family=@Family where PersonId=@PersonId ";


取消注释人员ID cmd.parameters行....
uncomment person id cmd.parameters line....


这篇关于调试后更新语句的异常.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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