if(dr.Read())
{
if(TextBox1.Text==dr["name"]&&TextBox2.Text==dr["password"].ToString())
{
Response.Write("<script>alert('登陆成功!')</script>");
//dr.Close();
}
else
{
Response.Write("<script>alert('用户或密码错误!')</script>");
}
dr.Close();
conn.Close();
{
if(TextBox1.Text==dr["name"]&&TextBox2.Text==dr["password"].ToString())
{
Response.Write("<script>alert('登陆成功!')</script>");
//dr.Close();
}
else
{
Response.Write("<script>alert('用户或密码错误!')</script>");
}
dr.Close();
conn.Close();
textbox2.text.trim()==dr["password"].tostring();再试~!
textbox1.text.trim()==dr["name"].ToString();
textbox2.text.trim()==dr["password"].ToString();
textbox2.text.trim()==dr["password"].tostring();错误:::C:\Inetpub\wwwroot\management_columns\WebForm1.aspx.cs(71): “string”并不包含对“trim”的定义
就是出不来结果~~~
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;namespace management_columns
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
SqlConnection conn;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string constr=ConfigurationSettings.AppSettings["dbconnstr"];
conn=new SqlConnection(constr);
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string selstr="select name,password from aa";
SqlCommand Comm=new SqlCommand(selstr,conn);
conn.Open(); SqlDataReader dr;
dr=Comm.ExecuteReader();
if(dr.Read())
{ if(TextBox1.Text==dr["name"].ToString()&&TextBox2.Text==dr["password"].ToString())
{
Response.Write("<script>alert('登陆成功!')</script>");
//dr.Close();
}
else
{
Response.Write("<script>alert('用户或密码错误!')</script>");
}
dr.Close();
conn.Close();
}
}
}
}
这是我的代码,数据库的用户名你也得字建下~~~
{
if(TextBox1.Text.ToString().Trim()==dr["name"].ToString().Trim()&&TextBox2.Text.ToString().Trim()==dr["password"].ToString().Trim())
{
Response.Write("<script>alert('登陆成功!')</script>");
//dr.Close();
}
else
{
Response.Write("<script>alert('用户或密码错误!')</script>");
}
dr.Close();
conn.Close();
textbox2.text==dr["password"].tostring().trim();
select 语句,后面,where name='"+textbox1.text+"'";
怎么加分你你们的??
将第一个if改为while也行
有QQ或MSN吗?下次有问题可以问问你
你的是不行啊,.trim()应该是在后面的,即:textbox1.text==dr["name"].tostring().trim();呵呵
{
// 假设第一列是Name,第二列是PassWord
if(TextBox1.Text==dr.GetString(0).Trim()&&TextBox2.Text==dr.GetString(1).Trim())
{
Response.Write("<script>alert('登陆成功!')</script>");
break;
}
else
{
Response.Write("<script>alert('用户或密码错误!')</script>");
}
}
dr.Close();
conn.Close();按照上面的试试看。