我正在使用此代码使用新值更新数据库。但它返回消息线程被中断。这是什么意思?我的代码出了什么问题?
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
答案 0 :(得分:4)
将Response.Redirect(ResolveClientUrl("~/Profil/"), false)
与Context.ApplicationInstance.CompleteRequest();
一起使用,而不是Response.Redirect(ResolveClientUrl("~/Profil/"))
查看Correct use of 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)