我试图创建一个用户可以编辑文本的网页,当他们完成后,他们点击保存并输入的新文本保存到数据库中。使用ContentEditable保存到DB与ASP.NET?
我没有在我的代码中发现任何错误,但由于某种原因,旧文本只是被重写入数据库而不是新文本。
这里是我的代码隐藏:
protected void saveBtn_Click(object sender, EventArgs e)
{
string newName;
string newIntro;
string newEduc;
string newWork;
h1New.Text = h1.Text;
newName = h1New.Text;
newIntro = intro.Text;
newEduc = educ.Text;
newWork = employ.Text;
string connectionInfo = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();
SqlCommand myCommand = new SqlCommand("UPDATE simpleContent SET userName = @newName, infoContent = @newIntro, educContent = @newEduc, workContent = @newWork WHERE userID = @userName", connection);
try
{
string username = HttpContext.Current.User.Identity.Name;
myCommand.Parameters.AddWithValue("@userName", username.ToString());
myCommand.Parameters.AddWithValue("@newName", newName.ToString());
myCommand.Parameters.AddWithValue("@newIntro", newIntro.ToString());
myCommand.Parameters.AddWithValue("@newEduc", newEduc.ToString());
myCommand.Parameters.AddWithValue("@newWork", newWork.ToString());
myCommand.ExecuteNonQuery();
connection.Close();
}
catch
{
Response.Redirect("http://www.google.co.uk");
}
}
}
我将不胜感激,你可能有任何指针。
你可以发布你目前拥有的代码在你的“的Page_Load”的方法? – Reinaldo 2012-04-12 16:11:42