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();

解决方案 »

  1.   

    <script language='javascript'>alert('登陆成功!')</script>
      

  2.   

    textbox1.text.trim()==dr["name"].tostring();
    textbox2.text.trim()==dr["password"].tostring();再试~!
      

  3.   

    试试下面的吧
    textbox1.text.trim()==dr["name"].ToString();
    textbox2.text.trim()==dr["password"].ToString();
      

  4.   

    textbox1.text.trim()==dr["name"].tostring();
    textbox2.text.trim()==dr["password"].tostring();错误:::C:\Inetpub\wwwroot\management_columns\WebForm1.aspx.cs(71): “string”并不包含对“trim”的定义
      

  5.   

    要转换为字符串....ToString()一下...
      

  6.   

    我本身就是这样的~~~ToString()
    就是出不来结果~~~
      

  7.   

    using System;
    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();
    }
    }
    }
    }
    这是我的代码,数据库的用户名你也得字建下~~~
      

  8.   

    if(dr.Read())
    {
    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();
      

  9.   

    textbox1.text==dr["name"].tostring().trim();
    textbox2.text==dr["password"].tostring().trim();
      

  10.   

    终于被我发现!
    select 语句,后面,where name='"+textbox1.text+"'";
      

  11.   

    MicroSoftor(http://blog.sina.com.cn/zhouzimimi) apologised() 两位的都行,呵呵,谢谢了啊
    怎么加分你你们的??
      

  12.   

    - -!
    将第一个if改为while也行
      

  13.   

    应该是需要".tostring().trim();
    有QQ或MSN吗?下次有问题可以问问你
      

  14.   

    textbox1.text.trim()==dr["name"].tostring();
    你的是不行啊,.trim()应该是在后面的,即:textbox1.text==dr["name"].tostring().trim();呵呵
      

  15.   

    估计有可能你的数据库中不只存在一条记录。你应该写一个循环取数据,如下:while (dr.Read())
    {
       // 假设第一列是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();按照上面的试试看。