.aspx.cs里的代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string TextBox1 = this.TextBox1.Text.ToString();
        string TextBox2 = this.TextBox2.Text.ToString();
        //数据库连接字符      
        String connectionString = "Server=localhost;Database=gwd;uid=sa;pwd=123;";
        //建立连接 
        SqlConnection conn = new SqlConnection(connectionString);
        //要执行的Sql语句 
        String cmdText = "select * from login where name='" + TextBox1 + "' and mima='" + TextBox2 + "'";
        //生成命名实例 
        SqlCommand command = new SqlCommand(cmdText, conn);
        //打开数据库 
        conn.Open();
        DataSet ds = new DataSet();
        int Counts;
        Counts = Convert.ToInt32(command.ExecuteScalar());
        if (Counts <= 0)
        {
            Response.Write("<script language='javascript'>alert('登陆失败!')</script>");
        }
        else
        {
            Response.Redirect("admin.aspx");
        }
        conn.Close();
    }
}Counts = Convert.ToInt32(command.ExecuteScalar())  提示确保参数格式正确 怎么改

解决方案 »

  1.   

    Counts = Convert.ToInt32(command.ExecuteScalar().ToString())
      

  2.   

       ExecuteScalar返回的值不一定可以转型为INT  你确定第一行第一列是INT吗
    //
            // 摘要:
            //     执行查询,并返回查询所返回的结果集中第一行的第一列。忽略其他列或行。
            //
            // 返回结果:
            //     结果集中第一行的第一列或空引用(如果结果集为空)。
            //
            // 异常:
            //   System.Data.SqlClient.SqlException:
            //     在对锁定的行执行该命令期间发生了异常。如果使用的是 Microsoft .NET Framework 1.0 版,将不会生成该异常。
            public override object ExecuteScalar();
      

  3.   

     Counts = Convert.ToInt32(command.ExecuteScalar()); 
    改为:string tmp = command.ExecuteScalar().ToString();看看 tmp 是什么值,说不定不是整数呢。
      

  4.   

    这个要怎么改?
    这样Counts = Convert.ToInt32(command.ExecuteScalar().ToString())改还是提示同样的错误~
      

  5.   

    根据你的程序的意图,应该这样改( * 改为 count(*) ):
    String cmdText = "select count(*) from login where name='" + TextBox1 + "' and mima='" + TextBox2 + "'"; 
      

  6.   

    对象不能转整形的,你这里不能用command.ExecuteScalar()这个方法
    要用这个  SqlDataReader objSqlReader = command.ExecuteReader();            if (objSqlReader.Read)
                {
                    Response.Redirect("admin.aspx");            }
                else
                {
                    Response.Write(" <script language='javascript'>alert('登陆失败!') </script>"); 
                }
      

  7.   

    根据你的程序的意图,应该这样改( * 改为 count(*) ):
      

  8.   

    试试
    counts = int.parse(command.ExecuteScalar().ToString())
      

  9.   

    把 * 改为 count(*) 后,Counts = Convert.ToInt32(command.ExecuteScalar()); 这句就不必加 .ToString() 了。(当然,加了也没错,不过有点多余。)
      

  10.   

    count(*) 是什么意思,能具体说一下count(*) 和* 的区别吗?
      

  11.   

    count(*) 是查询返回数据的数量,这样就可以确定返回值可以强转为整形