做登陆我的思路是这样的如果select 查到的记录大于0就行
可是我刚学不知道怎么得到select返回值
下面是我的代码大家帮一下忙 private void Button1_Click(object sender, System.EventArgs e)
{
string aa = TextBox1.Text.ToString();
string bb = TextBox2.Text.ToString();
string strSql = "select * from login where strName = '" +aa+ "' and strPassword = '" +bb+"'";
SqlConnection objConnection = new SqlConnection(conn);
objConnection.Open();
SqlCommand objCommand = new SqlCommand(strSql,objConnection);
objCommand.ExecuteNonQuery();
Response.Write(strSql);
if(objCommand.ExecuteNonQuery()!="")
{
Response.Write("登陆成功");
}
else
{
Response.Write("登陆失败");
}
}

解决方案 »

  1.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    string aa = TextBox1.Text.ToString();
    string bb = TextBox2.Text.ToString();
    string strSql = "select Count(*) from login where strName = '" +aa+ "' and strPassword = '" +bb+"'";
    SqlConnection objConnection = new SqlConnection(conn);
    objConnection.Open();
    SqlCommand objCommand = new SqlCommand(strSql,objConnection);
    string sCount = objCommand.ExecuteScalar().ToString();
    Response.Write(strSql);
    if(sCount !="1")
    {
    Response.Write("登陆成功");
    }
    else
    {
    Response.Write("登陆失败");
    }
    }
      

  2.   

    用SqlDataReader
    objCommand.ExecuteNonQuery();
    Response.Write(strSql);
    if(objCommand.ExecuteNonQuery()!="")
    {
    Response.Write("登陆成功");
    }
    else
    {
    Response.Write("登陆失败");
    }
    改成
    SqlDataReader reader=objCommand.ExecuteReader(CommandBehavior.SingleRow); if(reader.Read())
    {
    Response.Write("登陆成功"); }
    else
    {
    Response.Write("登陆失败");
    }
    reader.Close();
      

  3.   

    更正private void Button1_Click(object sender, System.EventArgs e)
    {
    string aa = TextBox1.Text.ToString();
    string bb = TextBox2.Text.ToString();
    string strSql = "select Count(*) from login where strName = '" +aa+ "' and strPassword = '" +bb+"'";
    SqlConnection objConnection = new SqlConnection(conn);
    objConnection.Open();
    SqlCommand objCommand = new SqlCommand(strSql,objConnection);
    string sCount = objCommand.ExecuteScalar().ToString();
    Response.Write(strSql);
    if(sCount =="1")
    {
    Response.Write("登陆成功");
    }
    else
    {
    Response.Write("登陆失败");
    }
    }