当前位置:编程学习 > C#/ASP.NET >>

为什么提示等号附近有错误

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace mystudynew
{
/// <summary>
/// mainf 的摘要说明。
/// </summary>
public class mainf : System.Web.UI.Page
{
protected System.Web.UI.WebControls.AdRotator AdRotator1;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.LinkButton LinkButton3;
protected System.Web.UI.WebControls.LinkButton LinkButton4;
protected System.Web.UI.WebControls.LinkButton LinkButton5;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lblTime;
protected System.Web.UI.WebControls.TextBox txtSearch;
protected System.Web.UI.WebControls.DropDownList ddlCategory;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.LinkButton LinkButton7;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.LinkButton LinkButton6;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Application.Lock();
if(Application["PageCounter"]==null)
{
Application["PageCounter"]=0;
}
Application["PageCounter"]=(int)Application["PageCounter"]+1;
this.Label1.Text =Convert.ToString(Application["PageCounter"]);
Application.UnLock();

if(!this.IsPostBack)
{
SqlConnection con=mystudy.connectdb.connectdatabase();
con.Open();

SqlCommand cmd=new SqlCommand("select * from categories",con);
SqlDataReader sdr=cmd.ExecuteReader();                         为什么提示等号附近有错误??
this.DataGrid1.DataSource=sdr;
this.DataGrid1.DataBind();
sdr.Close();

cmd.CommandText="select username from userinfo where userid="+Session["userid"];
                string uname = cmd.ExecuteScalar().ToString();
                this.Label2.Text=uname;
    this.Label3.Text=DateTime.Today.ToShortDateString();
this.Label4.Text=DateTime.Today.DayOfWeek.ToString();





}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
this.LinkButton4.Click += new System.EventHandler(this.LinkButton4_Click);
this.LinkButton5.Click += new System.EventHandler(this.LinkButton5_Click);
this.LinkButton6.Click += new System.EventHandler(this.LinkButton6_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{


}

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
// this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
//
//// SqlConnection con=mystudy.connectdb.connectdatabase();
//// con.Open();
//// SqlCommand cmd=new SqlCommand("select * from categories",con);
//// SqlDataReader sdr=cmd.ExecuteReader();
//// this.DataGrid1.DataSource=sdr;
//// this.DataGrid1.DataBind();



}

private void LinkButton1_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("main.aspx");
}

private void LinkButton2_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("showdetails.aspx?CateID=1");
}

private void LinkButton3_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("showdetails.aspx?CateID=2");

}

private void LinkButton4_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("showdetails.aspx?CateID=3");
}

private void LinkButton5_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("showdetails.aspx?CateID=4");
}

private void LinkButton6_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("showdetails.aspx?CateID=5");
}

private void Button1_Click(object sender, System.EventArgs e)
{
string strproname=this.txtSearch.Text;
string icateid=this.ddlCategory.SelectedValue;
this.Response.Redirect("Seachresults.aspx?ProductName="+ strproname+"&CategoryID="+icateid);

}


}
}
--------------------编程问答-------------------- cmd.CommandText="select username from userinfo where userid="+Session["userid"]; 
恐怕错的是这句。。userid是整型的? --------------------编程问答-------------------- userid 是整型的
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,