我的数据库中有 ProductID 列,我想将当前项目 ID 添加到此列。我试过这个,但它不起作用:
private void InsertInfo()
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO CommentsTable (Name, Email, Comment, ProductID) VALUES (@Name,@Email,@Comment,@ProductID)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@Name", TextBox1.Text);
cmd.Parameters.AddWithValue("@Email", TextBox2.Text);
cmd.Parameters.AddWithValue("@Comment", TextBox3.Text);
cmd.Parameters.AddWithValue("@ProductID", Sitecore.Context.Item.ID.ToString());
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
提前致谢。