我在我的数据库中有ProductID列,我想将当前项目ID添加到此列。我试过了,但它不起作用:在sitecore中将当前项目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();
}
提前致谢。
任何异常或错误消息? –
System.ArgumentNullException:值不能为空。 – User
在哪一行?请调试您的代码。 –