private void Button1_Click(object sender, System.EventArgs e)
{
     SqlConnection myConnection=new SqlConnection("server=(local);uid=sa;pwd=;database=li");
  SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"',mima='"+TextBox2.Text+"'",myConnection);//这句查询语句好象从数据库中找不到文本框输入的内容.....怎么改
try
{
myConnection.Open();
    mySqlCommand.ExecuteReader();
Response.Redirect("WebForm3.aspx");
}
catch(Exception)
{
Label3.Text="没有此用户名".ToString();
}
finally
{
myConnection.Close();
}

}

解决方案 »

  1.   

    呵呵,语法错误吧!!!
    select name,mima from denglu where name='"+TextBox1.Text+"',mima='"+TextBox2.Text+"'"
    可以像这样写吗?多条件查询要用AND联接还不是用“,”
    select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'"
    而且你的密码怎么加密算法都没有一个呢?
      

  2.   

    从数据库中找不到文本框输入的内容?什么意思?
    myConnection.Open();
        mySqlCommand.ExecuteReader();
    Response.Redirect("WebForm3.aspx");
    找不到数据也不会产生异常的。
      

  3.   

    SqlConnection myConnection=new SqlConnection("server=local);uid=sa;pwd=****(没有写啊);database=li");
     SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
    try
    {
    myConnection.Open();
        mySqlCommand.ExecuteReader();
    Response.Redirect("WebForm3.aspx");
    }
    catch(Exception)
    {
    Label3.Text="没有此用户名".ToString();
    }
    finally
    {
    myConnection.Close();
    }
    我在WebForm1.aspx中拖了两个TextBox  一个提交botton 在文本框中输入用户名.密码,,然后在数据库中查询,查到转到WebForm3.aspx页面,,查询好像有问题啊,我数据库中已经有信息了,可是输入查询总是Label3显示"没有此用户名".
      

  4.   

    应该先打开数据库,再去查询
    SqlConnection myConnection=new SqlConnection("server=local);uid=sa;pwd=****(没有写啊);database=li");
          myConnection.Open();
     SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
    try
    {

        mySqlCommand.ExecuteReader();
    Response.Redirect("WebForm3.aspx");
    }
    catch(Exception)
    {
    Label3.Text="没有此用户名".ToString();
    }
    finally
    {
    myConnection.Close();
    }
      

  5.   

    SqlConnection myConnection=new SqlConnection("server=local);uid=sa;pwd=****(没有写啊);database=li");
          
     SqlCommand mySqlCommand=new SqlCommand("select name,mima from denglu where name='"+TextBox1.Text+"' And mima='"+TextBox2.Text+"'",myConnection);
    SqlDataReader dr;
    try
    {
    myConnection.Open();
        dr = mySqlCommand.ExecuteReader();
    if(dr.read())
    {
    Response.Redirect("WebForm3.aspx");
    }
    else
    {
    Label3.Text="没有此用户名".ToString();
    }
    }
    catch(Exception E)
    {
    Response.Write(E.Message);
    }
    finally
    {
    myConnection.Close();
    }