0
我有一个字段窗体有一个编辑器,我试图更新我的数据库。我可以填充表单数据并将其解码以供显示,但我无法将其更新。下面的代码来自我的提交按钮,我正在做两件事情将内容编码并保存到数据库中。我没有收到任何错误只是刷新页面。我发现的语法看起来很正确。VB简单的窗体使用SqlCommand更新数据库
在下面的例子中,“CKEditorControl1”是我所见即所得的文本编辑器。它输出我试图编码和保存的html。
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim section = Page.Request.Params("SectionName")
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString)
conn.Open()
Dim command As New SqlCommand("UPDATE PageContent SET SectionBody = @SectionBody WHERE SectionName = @SectionName", conn)
command.Parameters.AddWithValue("@SectionName", section.ToString())
command.Parameters.AddWithValue("@SectionBody", Server.HtmlEncode(CKEditorControl1.Text))
command.ExecuteNonQuery()
conn.Close()
End Sub
为什么使用'AddWithValue(“@ SectionBody”,Server.HtmlEncode(CKEditorControl1.Text))'还有'command.Parameters(“@ SectionBody”)。Value = Server.HtmlEncode(CKEditorControl1.Text)''。这并不是说这应该是一个问题,但其中一个是多余的。你用过调试器吗? – 2014-09-04 19:47:07
如果你没有收到错误,我假设'Where SectionName = @ SectionName'没有得到正确的字符串,因此找不到要更新的行。运行'msgBox(section.ToString())'来查看。 – Cory 2014-09-04 20:37:37
@Tim谢谢。我真的没有看到每个人的差异,但不知道是否有人比其他人更喜欢更新。我更新了我的样本。调试器不会给我提供很多线索,因为页面只是刷新。 – tree 2014-09-04 21:35:13