using System;
using System.Data;
using System.Configuration;
using System.Web.Configuration;
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;public partial class _Default : System.Web.UI.Page
{ static string strConnect = System.Configuration.ConfigurationManager.AppSettings["checkinConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection objConnection = new SqlConnection(strConnect);
SqlCommand objCommand = new SqlCommand("", objConnection);
objCommand.CommandText = "SELECT Username,Password FROM userinfo WHERE USERNAME = @NAME AND Password = @PASSWORD";
objCommand.Parameters.Add("NAME", SqlDbType.VarChar);
objCommand.Parameters.Add("PASSWORD", SqlDbType.VarChar);
objCommand.Parameters["NAME"].Value = tbxName.Text.Trim();
objCommand.Parameters["PASSWORD"].Value = tbxPassword.Text.Trim();
objConnection.Open();
SqlDataReader result = objCommand.ExecuteReader();
if (result.Read() == true)
{
//objCommand.ExecuteNonQuery();
Response.Redirect("loginsuc.aspx");
}
else
{
Response.Redirect("error.aspx");
}
objConnection.Close(); }
protected void btnCancel_Click(object sender, EventArgs e)
{
tbxName.Text = "";
tbxPassword.Text = "";
labError.Visible = false;
}
}web.config里
<connectionStrings>
<add name="checkinConnectionString" connectionString="Data Source=(local);Initial Catalog=checkin;User ID=sa;Asynchronous Processing=True"
providerName="System.Data.SqlClient" />
</connectionStrings>运行时说,ConnectionString 属性尚未初始化
指向objConnection.Open();这句
请问这个问题怎么解决.
我想要实现的是登陆验证用户名和密码的问题
有高手有另外的思路也可以说来听听?!
using System.Data;
using System.Configuration;
using System.Web.Configuration;
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;public partial class _Default : System.Web.UI.Page
{ static string strConnect = System.Configuration.ConfigurationManager.AppSettings["checkinConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection objConnection = new SqlConnection(strConnect);
SqlCommand objCommand = new SqlCommand("", objConnection);
objCommand.CommandText = "SELECT Username,Password FROM userinfo WHERE USERNAME = @NAME AND Password = @PASSWORD";
objCommand.Parameters.Add("NAME", SqlDbType.VarChar);
objCommand.Parameters.Add("PASSWORD", SqlDbType.VarChar);
objCommand.Parameters["NAME"].Value = tbxName.Text.Trim();
objCommand.Parameters["PASSWORD"].Value = tbxPassword.Text.Trim();
objConnection.Open();
SqlDataReader result = objCommand.ExecuteReader();
if (result.Read() == true)
{
//objCommand.ExecuteNonQuery();
Response.Redirect("loginsuc.aspx");
}
else
{
Response.Redirect("error.aspx");
}
objConnection.Close(); }
protected void btnCancel_Click(object sender, EventArgs e)
{
tbxName.Text = "";
tbxPassword.Text = "";
labError.Visible = false;
}
}web.config里
<connectionStrings>
<add name="checkinConnectionString" connectionString="Data Source=(local);Initial Catalog=checkin;User ID=sa;Asynchronous Processing=True"
providerName="System.Data.SqlClient" />
</connectionStrings>运行时说,ConnectionString 属性尚未初始化
指向objConnection.Open();这句
请问这个问题怎么解决.
我想要实现的是登陆验证用户名和密码的问题
有高手有另外的思路也可以说来听听?!
objConnection.Open();
<add name="checkinConnectionString" connectionString="Data Source=(local);Initial Catalog=checkin;User ID=sa;Asynchronous Processing=True"
providerName="System.Data.SqlClient" />
</connectionStrings>2.0用static string strConnect = System.Configuration.ConfigurationManager.ConnectionStrings["checkinConnectionString"].ToString();