请各位大虾指教一个问题!!
我想做一个登陆后,查询登录者在sql数据库里信息的页面,但老报错,应该怎么写比较好,本人初学菜鸟,求教!!谢谢public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=;database=contacts;uid=;pwd=;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from tb_gongzi where userName='" + Session["userName"].ToString() + "'");
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.lblUsername.Text = sdr["userName"].ToString();
this.lblGongzi.Text = sdr["csGongzi"].ToString();
this.lblKoukuan.Text = sdr["csJiaofei"].ToString();
}
}
}
ExecuteReader: Connection 属性尚未初始化。报这样的错!!
this.lblUsername.Text = sdr["userName"].ToString(); 也没有定义