1

我正在使用此代码用新值更新数据库。但它返回消息线程被中断。这是什么意思?我的代码有什么问题?

 Dim connStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("DeskriptivaConnectionString").ConnectionString.ToString()
    Dim txtName As Object = DirectCast(FormView1.FindControl("txtName"), TextBox)
    Dim txtLastName As Object = DirectCast(FormView1.FindControl("txtLastName"), TextBox)
    Dim txtInfo As Object = DirectCast(FormView1.FindControl("txtInfo"), TextBox)
    Dim txtCity As Object = DirectCast(FormView1.FindControl("txtCity"), TextBox)
    Dim txtPrize As TextBox = DirectCast(FormView1.FindControl("txtPrize"), TextBox)
    Dim txtPhone As TextBox = DirectCast(FormView1.FindControl("txtPhone"), TextBox)
    Dim txtMail As TextBox = DirectCast(FormView1.FindControl("txtMail"), TextBox)


    Try
        Using conn As New SqlConnection(connStr)
            Dim cmd As SqlCommand = conn.CreateCommand()
            cmd.CommandText = "UPDATE Profiles SET @Name = Name, @LastName = LastName, @Info = Info, @City = City, @Prize = Prize, @Phone = Phone, @Mail = Mail WHERE (UserName = @UserName)"
            cmd.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar).Value = txtName.Text
            cmd.Parameters.Add("@LastName", System.Data.SqlDbType.NVarChar).Value = txtLastName.Text
            cmd.Parameters.Add("@Info", System.Data.SqlDbType.NText).Value = MakeLink(HtmlRemoval.StripTagsCharArray(txtInfo.Text))
            cmd.Parameters.Add("@City", System.Data.SqlDbType.NVarChar).Value = txtCity.Text
            cmd.Parameters.Add("@Prize", System.Data.SqlDbType.NVarChar).Value = txtPrize.Text
            cmd.Parameters.Add("@Phone", System.Data.SqlDbType.NVarChar).Value = txtPhone.Text
            cmd.Parameters.Add("@Mail", System.Data.SqlDbType.NVarChar).Value = txtMail.Text
            cmd.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar).Value = Context.User.Identity.Name

            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
            Response.Redirect(ResolveClientUrl("~/Profil/"))
        End Using

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
4

1 回答 1

3

使用Response.Redirect(ResolveClientUrl("~/Profil/"), false)withContext.ApplicationInstance.CompleteRequest();代替Response.Redirect(ResolveClientUrl("~/Profil/"))

检查正确使用 System.Web.HttpResponse.Redirect博客文章以获取更多信息

而且你的 sql 参数 @ 符号在错误的地方。更改如下

UPDATE Profiles SET Name = @Name, LastName = @LastName, Info = @Info, City = @City, Prize = @Prize, Phone = @Phone, Mail = @Mail WHERE (UserName = @UserName)

于 2013-07-15T07:01:26.867 回答