我想把textbox里的数据读出来存到数据库中,数据库中的余额字段是decimal类型,
       Session["UserName"] = "yiyi";
        decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
        Label16.Text = Session["UserName"].ToString();//要更新的用户名
        SqlConnection conn = new SqlConnection("Data Source=;Integrated Security=True");
        conn.Open();
        string sqlstr1 = "update UserInfo set Account= account where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal,如何写update语句???
        SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
        cmd1.ExecuteNonQuery();

解决方案 »

  1.   

    直接作为string处理
    update UserInfo set Account= ‘“+account+”’ where BuyerName=='" + Session["UserName"] + "'
     
      

  2.   

     Session["UserName"] = "yiyi";
            decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
            Label16.Text = Session["UserName"].ToString();//要更新的用户名
            SqlConnection conn = new SqlConnection("Data Source=WWW-89CBDBACAB5\\SQLEXPRESS;Initial Catalog=G:\\ESHOP\\APP_DATA\\PaiMai.MDF;Integrated Security=True");
            conn.Open();
            string sqlstr1 = " update UserInfo set Account= '"+account+"' where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
            SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
            cmd1.ExecuteNonQuery();
    有错误:输入格式不正确
      

  3.   

    确定 TextBox1.Text 不为字符? sql没错 您传过来的值确认下!
      

  4.   

    string sqlstr1 = " update UserInfo set Account= '"+account+"' where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
    是where buyername=
    一个=号不是两个
      

  5.   

    确保你的string值是数值型的。
    decimal.Parse(str)
      

  6.   

    string sqlstr1 = " update UserInfo set Account= '"+decimal.Parse(account)+"' where BuyerName=='" + Session["UserName"] + "'";//确保你的string值是数值型的
      

  7.   


    string sqlstr1 = " update UserInfo set Account= "+account+" where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
      

  8.   

    不是2个= ,sql没有==;
    有错误:输入格式不正确
    说明是你传过来的值有问题 !
      

  9.   

    update UserInfo set Account= '"+account+"' where BuyerName='" + Session["UserName"].ToString()+'" 
      

  10.   

    Session["UserName"] = "yiyi";
    decimal account  = 0.0;
    try
    {
        account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
    }
    catch(Exception )
    {
       ClientScript.RegisterClientScriptBlock(GetType(),"","<script>alert('输入的必须是数字!')</script>");
        return;
    }

      Label16.Text = Session["UserName"].ToString();//要更新的用户名
      SqlConnection conn = new SqlConnection("Data Source=;Integrated Security=True");
      conn.Open();
      string sqlstr1 = "update UserInfo set Account="+account+" where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal,如何写update语句???
      SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
      cmd1.ExecuteNonQuery();
      

  11.   

    decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
    try catch下。
    ps:TextBox1.Text.Trim().已经是字符串了。