using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;public partial class Receive : System.Web.UI.Page
{
    protected string v_oid; // 订单号
    protected string v_pstatus; // 支付状态码
    //20(支付成功,对使用实时银行卡进行扣款的订单);
    //30(支付失败,对使用实时银行卡进行扣款的订单);    protected string v_pstring; //支付状态描述
    protected string v_pmode; //支付银行
    protected string v_amount; //支付金额
    protected string v_moneytype; //币种
    protected string re1; // 备注1
    protected string re2; // 备注1
    protected string v_md5str;
    protected string status_msg;
    protected string str; // 备注1
    protected void Page_Load(object sender, EventArgs e)
    {
        // MD5密钥要跟订单提交页相同,如Send.asp里的 key = "test" ,修改""号内 test 为您的密钥
        string key = "13880604309171471"; // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
        // 登陆后在上面的导航栏里可能找到“B2C”,在二级导航栏里有“MD5密钥设置”
        // 建议您设置一个16位以上的密钥或更高,密钥最多64位,但设置16位已经足够了        v_oid = Session["Accounts"].ToString();
        v_pstatus = Request["v_pstatus"];
        v_pstring = Request["v_pstring"];
        v_pmode = Request["v_pmode"];
        v_md5str = Request["v_md5str"];
        v_amount = Session["amount"].ToString();
        v_moneytype = Request["v_moneytype"];
        re1 = Request["re1"];
        re2 = Request["re2"];        string str = v_oid + v_pstatus + v_amount + v_moneytype + key;        str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper();            if (str == v_md5str)
        {            if (v_pstatus.Equals("20"))
            {
                int UserID = 0;
                string name = v_oid;
                int amount =Convert.ToInt32(v_amount);//报错说输入格式不正确
                SqlConnection con = DBL.DBhelper.getConnection();
                con.Open();
                SqlCommand cmd = new SqlCommand("select UserID from AccountsInfo where Accounts='" + name + "'", con);
                SqlDataReader dr = cmd.ExecuteReader();
                if(dr.Read())
                {
                    UserID = int.Parse(dr[0].ToString());
                }
                con.Close();
                SQLServerDAL.DAlScore.InsertGamecong(UserID, amount);
                int Score = SQLServerDAL.DAlScore.SelectScore(UserID);
                int Score1 = (amount * 1000) + Score;
                SQLServerDAL.DAlScore.UpScore(UserID, Score1);
            }
        }
        else
        {

            status_msg="校验失败,数据可疑" ;
        }
    }
}int amount =Convert.ToInt32(v_amount);//报错说输入格式不正确

解决方案 »

  1.   

    v_amount 是string型的,转为int型出错可能里面部分内容转int时出错。
    你可以debug看下从Session中抓出的v_amount是什么? 正常吗?
      

  2.   

    一个字符串转换的问题。你说一个钱的值,你设置成int干嘛?
    还0.01,明明知道钱有角分的撒。- -
      

  3.   


    int amount =Convert.ToInt32(v_amount);//报错说输入格式不正确改为float类型
      

  4.   

    int amount =Convert.ToInt32(v_amount);//报错说输入格式不正确// 改为:double amount = double.Parse(v_amount);
      

  5.   

    decimal amount = deciaml.Parse(v_amount); // 用 decimal 更好些
      

  6.   

    上面的 deciaml 改为 decimal,打字太快了,笔误。
      

  7.   

    decimal pay = Convert.ToDecimal(v_amount);
      

  8.   

    int amount =Convert.ToInt32(v_amount);
    改成:
    double amount = Convert.ToDouble(v_amount);int Score1 = (amount * 1000) + Score;
    改成:
    int Score1 +=(int)((amount * 1000) + Score);