尝试插入用户在我的 UPDATE SQL 语句下编辑的评论时遇到此错误。由于我的 UserId 是一个 uniqueIdentifier,我真的不知道如何解决这个错误。
错误显示:
Cannot insert the value NULL into column 'UserId', table
我的 .cs 代码是:
int CommentID = int.Parse(ListView1.DataKeys[e.ItemIndex].Value.ToString());
ListViewItem item = ListView1.Items[e.ItemIndex];
TextBox Title = (TextBox)item.FindControl("Title");
TextBox commentContent = (TextBox)item.FindControl("commentContent");
string connectionString = ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString1"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
string sql = "Update Comments set Title = @Title, commentContent=@commentContent where CommentID = @CommentID";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@Title", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@commentContent", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@CommentID", CommentID);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}