SqlDataBase ThisB = new SqlDataBase();
        string CheckSql = "select count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
        int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));这里老是说:System.FormatException: 输入字符串的格式不正确。出错就错在:int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql))这行,请问该怎么处理,请高手指点下,我看到有人网上说这里输出下,可是我这个是在一个cs文件的类里,我该怎么输出,用response.write又说不允许使用。求教,求教,我是.net新手

解决方案 »

  1.   

    public static int getCount()
    {
    SqlDataBase ThisB = new SqlDataBase();
            string CheckSql = "select count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
            int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));  return ThisNum;}
      

  2.   

    你先看(ThisB.ReturnSQL(CheckSql))拿到的是什么
      

  3.   

    object ob=ThisB.ReturnSQL(CheckSql);
    看看是什么
      

  4.   

    ThisB.ReturnSQL()方法的返回值有问题~
      

  5.   

    输入字符串的格式不正确 就看看输入的是什么呗,是不是不能转换成int
      

  6.   

    ReturnSQL返回的什么呀?
    CheckSql不就是返回的count吗
      

  7.   

    SqlDataBase ThisB = new SqlDataBase();
    tring CheckSql = "select count(*) from UserList where [UserName] = '" + UserName + "' and [PassWord] = '" + PassWord + "'";System.Web.HttpContext.Current.Response.Write(ThisB.ReturnSQL(CheckSql)); //看是什么
    //int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));
      

  8.   

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;/// <summary>
    /// CheckLogin 的摘要说明
    /// </summary>
    public class CheckLogin
    {
    public CheckLogin()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
        public int GiveID(string UserName, string PassWord) 
        {
            SqlDataBase ThisB = new SqlDataBase();
            string CheckSql = "select count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
            System.Web.HttpContext.Current.Response.Write(ThisB.ReturnSQL(CheckSql)); 
            int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));
            if (ThisNum > 0)
            {
                string SqlType = "select * from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
                SqlDataReader ThRead = ThisB.GRead(SqlType);
                while (ThRead.Read())
                {
                    return Convert.ToInt32(ThRead["ID"]);
                }
            }
            return 0;
        }    private void mbox(string p)
        {
            throw new NotImplementedException();
        }
        public static bool CheckAdmin(int UserID) 
        {
            SqlDataBase MyDb = new SqlDataBase();
            string Log = Convert.ToString(MyDb.ReturnSQL("select UserType from UserList Where ID = '" + UserID + "'"));
            if (Log == "1")
            {
                return true;
            }
            else 
            {
                return false;
            }
        }
        public static int GiveCheckAd(int UserID) 
        {
            SqlDataBase MyDb = new SqlDataBase();
            int Log = Convert.ToInt32(MyDb.ReturnSQL("select GoodsType from UserList Where ID = '" + UserID + "'"));
            return Log;
        }
        public static DataTable GiveMsgGod(int UserID) //返回对应仓库的数量超限产品
        {
            SqlDataBase MyDb = new SqlDataBase();
            int Log = Convert.ToInt32(MyDb.ReturnSQL("select Controls from UserList Where ID = '" + UserID + "'"));
            string SqlString = "";
            if (Log == 0)
            {
                SqlString = "select * from View_GoodMsg";
            }
            else 
            {
                SqlString = "select * from View_GoodMsg where ID = '"+Log+"'";
            }
            return MyDb.DT(SqlString);
        }
        public static bool CheckKeepAdmin(int UserID) 
        {
            SqlDataBase MyDb = new SqlDataBase();
            string Log = Convert.ToString(MyDb.ReturnSQL("select GoodsType from UserList Where ID = '" + UserID + "'"));
            if (Log == "0")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
      

  9.   

    public class SqlDataBase
    {
        public SqlDataBase()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //    }
        private SqlConnection Cn;
        private SqlCommand Cm;
        private DataSet ds;
        private DataView dv;    #region
        private void Open()
        {
            Cn = new SqlConnection(ConfigurationSettings.AppSettings["Dsn"]);
            Cn.Open();
        }
        #endregion    #region 关闭连接
        private void Close()
        {
            if (Cn != null)
            {
                Cn.Close();
                Cn.Dispose();
            }
        }
        #endregion    #region 执行简单的SQL语句
        public void NoreturnSql(string Sql)
        {
            Open();
            Cm = new SqlCommand(Sql, Cn);
            Cm.ExecuteNonQuery();
            Close();
        }
        #endregion
      

  10.   

    我把两个文件的代码都贴出来了,我就是看不来,这个ThisB.ReturnSQL(CheckSql)到底返回了什么,但数据库中,用select count(*)就算没记录也应该返回0,不应该是null的,是吧?
      

  11.   

    int ThisNum = int.Parse(ThisB.ReturnSQL(CheckSql).ToString().Trim());
      

  12.   


    怎么没看见ReturnSQL(CheckSql)这个函数?
      

  13.   


    异常详细信息: System.FormatException: 输入字符串的格式不正确。源错误: 
    行 26:         string CheckSql = "select count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
    行 27: //        System.Web.HttpContext.Current.Response.Write(ThisB.ReturnSQL(CheckSql));
    行 28:         int ThisNum =  int.Parse(ThisB.ReturnSQL(CheckSql).ToString().Trim());
    行 29: 
    行 30:         //int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));
     源文件: d:\WuZiGuanLi_51aspx\App_Code\CheckLogin.cs    行: 28 还是不行啊
      

  14.   

    你的 ThisB.ReturnSQL(CheckSql) 这个是什么, Convert.ToInt32() 一般是将 object型的数据转成int型的,其他的转换方式像 int.Parse() 是把字符串型转成 int型。。
      

  15.   

    大家没有说到重点应该是
    SqlDataBase ThisB = new SqlDataBase();
            string CheckSql = "Declare @RowCount int ;select RowCount =count(*) from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "' RETURN RowCount  ";
            int ThisNum = Convert.ToInt32(ThisB.ReturnSQL(CheckSql));试试。准可以!
      

  16.   

    还是没成功,我觉得可能是我的问题,因为我刚开始弄.net,我先自己再检查下,是否我别的地方有什么错误,没发现
      

  17.   

    应该是ReturnSQL函数问题,把你这个函数发出来看下
      

  18.   

    应该是ReturnSQL函数问题,把你这个函数发出来看下 
      

  19.   


     public DataRow GetRow(string Sqlstr)
        {        SqlDataAdapter da = new SqlDataAdapter(Sqlstr, Sqlcoon);
            DataSet ds = new DataSet();        da.Fill(ds, "TableName");
            return ds.Tables[0].Rows[0];
        }SqlDataBase ThisB = new SqlDataBase();
            string CheckSql = "select count(*) as Cut from UserList where UserName = '" + UserName + "' and PassWord = '" + PassWord + "'";
         
     DataRow dr = GetRow(CheckSql);
     int count = System.Convert.ToInt32(dr["Cut"].ToString());这样就可以了
      

  20.   

     如果你的字符串是数字类型的比如这样string uints="485211"; 这样的字符串可以转换不会报错,如果你是string uints="sadads";这样的,就转换出错了!!!