ConnectionString 属性尚未初始化
初学之中....
望高人指点。。。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void InitializeComponent()
{
this.btlogin.Click += new System.EventHandler(this.btlogin_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
protected void btlogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["managermentConnectionString"];
con.Open();
string loginsql = "select User_name,password from reg_users where user_name='" + user_name.Text + "' and password='" + password.Text + "'";
SqlCommand com=new SqlCommand(loginsql,con);
SqlDataReader dr=com.ExecuteReader();
bool btExist=false;
while(dr.Read())
{
btExist=true;
Session["UserName"]=dr.GetString(0);
Session["PassWord"]=dr.GetString(1);
}
if(btExist)
Response.Redirect("index.htm");
else
Response.Write("<script language='javascript'>alert('用户名或密码错误!')</script>");
con.Close();
}
}
web.config中配置如下:
<connectionStrings>
<add name="managermentConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\website\App_Data\managerment.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
出现ConnectionString 属性尚未初始化!