If you're looking for the ID of the product you're currently browsing you can just use: Sitecore.Context.Item.ID
. If you can't use that, you'll have to make sure that your querystring actually exists and has a value. With Sitecore you can use: Sitecore.Web.WebUtil.GetQueryString("id", string.Empty)
where the string.Empty
can be replaced with whatever you want the default value to be.
Adding current item id into db in sitecore
Frage
I have ProductID column in my db and I want to add current item id to this column. I've tryed this, but it doesn't work:
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();
}
Thank's in advance.
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow