string artname = TextBox5.Text;
        string artdes = TextBox6.Text;
        decimal artprice =Convert.ToDecimal(TextBox7.Text);
        SqlConnection cn = new SqlConnection("server=(local);database=MPDB; uid=sa; pwd =sa");
        SqlCommand cm = new SqlCommand("insert into MP_Info(ArtName,ArtDescription,ArtPrice) values ('" + artname + "','" + artdes + "','"+ artprice +"') ", cn);
        cn.Open();
        cm.ExecuteNonQuery();
        cn.Close();
       试图实现以上代码,但是总是提示varchar类型无法转换成money类型的,到底是为什么,money类型该如何插入数据库。

解决方案 »

  1.   

    decimal artprice =decimal.parse(TextBox7.Text); 这样试试那
      

  2.   

    不要加单引号 SqlCommand cm = new SqlCommand("insert into MP_Info(ArtName,ArtDescription,ArtPrice) values ('" + artname + "','" + artdes + "',"+ artprice +") ", cn); 
      

  3.   

     SqlCommand cm = new SqlCommand("insert into MP_Info(ArtName,ArtDescription,ArtPrice) values ('" + artname + "','" + artdes + "','"+ artprice +"') ", cn); 
    把后面的'"+ artprice +"' 的 单引号去掉