出现问题:
原代码:
public partial class Details : System.Web.UI.Page
{
string id;
protected void Page_Load(object sender, EventArgs e)
{
id = Request.QueryString["id"];
//if (Session["UserID"] == null)
//{
// Response.Write("<script language='javascript'>alert('请登录后再进行操作');window.location.href='User/Login.aspx';</script>");
//}
if (!this.IsPostBack)
{
Bind();
}
}
public void Bind()
{
// string str = "Select * From movies where movieid ="+id + "";
string str = "select * from Movies where MovieName like '%" + Session["MovieName"].ToString() + "%'";
SqlConnection con = DB.getConnection();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(str, con);
sda.Fill(ds, "Movie");
this.DataList1.DataSource = ds.Tables["Movie"].DefaultView;
this.DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Play")
{
string hit = (e.Item.FindControl("Label8") as Label).Text; //当前的点播次数
string getmovieid = (e.Item.FindControl("Lable20") as Label).Text;//当前所选择的视频ID号
int num = Convert.ToInt32(hit) + 1;
SqlConnection con = DB.getConnection();
if (con.State != ConnectionState.Open)
{
con.Close();
con.Open();
}
SqlCommand cmd = new SqlCommand("Update Movies set moviehit = " + num + " where movieid =" + getmovieid + "", con);
cmd.ExecuteNonQuery();//执行更新的语句
con.Close();
Response.Redirect("Play.aspx?ID=" + getmovieid);
}
}
}