代码如下:
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;public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
Response.Write("success");
Response.Redirect("Home.aspx");
} }
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{ bool boolReturnValue = false; // Insert code that implements a site-specific custom // authentication method here. // This example implementation always returns false. string strConnection = "server=(local);database=huatian-info;uid=sa;pwd=;"; SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From User"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr; Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read())
{ if ((UserName == Dr["User_Code"].ToString()) & (Password == Dr["Password"].ToString()))
{ boolReturnValue = true; break; } } Dr.Close(); return boolReturnValue; }}错误提示:
源错误:
行 52: SqlDataReader Dr;
行 53:
行 54: Connection.Open();
行 55:
行 56: Dr = command.ExecuteReader();
源文件: e:\web\huatian-info\login.aspx.cs 行: 54 请帮忙告诉原因 谢谢 解决后马上散分!
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;public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
Response.Write("success");
Response.Redirect("Home.aspx");
} }
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{ bool boolReturnValue = false; // Insert code that implements a site-specific custom // authentication method here. // This example implementation always returns false. string strConnection = "server=(local);database=huatian-info;uid=sa;pwd=;"; SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From User"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr; Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read())
{ if ((UserName == Dr["User_Code"].ToString()) & (Password == Dr["Password"].ToString()))
{ boolReturnValue = true; break; } } Dr.Close(); return boolReturnValue; }}错误提示:
源错误:
行 52: SqlDataReader Dr;
行 53:
行 54: Connection.Open();
行 55:
行 56: Dr = command.ExecuteReader();
源文件: e:\web\huatian-info\login.aspx.cs 行: 54 请帮忙告诉原因 谢谢 解决后马上散分!
String strConnection="Data Source=(local);Initial Catalog=huatian-info;uid=sa;pwd=;"
行 55: Connection.Open();
行 56:
行 57: Dr = command.ExecuteReader();
行 58:
---------------------------------------------------------------------------
最后引号里的那个分号去掉!
散分