| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 599 人关注过本帖
标题:varchar到money的转换?
只看楼主 加入收藏
littldoudou
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2009-8-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
varchar到money的转换?
try
            {
                string  shipname1 = this.TextBox1.Text.Trim();
                string companyname1 = this.TextBox3.Text.Trim();
                string portofregistry1 = this.TextBox5.Text.Trim();
                string  peccancytime1 =  this.Text1.Value.ToString().Trim();
                string peccancyplace1 =this.TextBox2.Text.Trim();
                string  peccancyreason1 =  this.TextBox4.Text.Trim();
                Decimal  peccancymoney1 = Convert.ToDecimal(this.TextBox6.Text.Trim());
                string pk = shipname1 + peccancytime1;
               
                Regex re=new Regex(@"^[0-9]+$");
                //连接数据库
                string strConnection = "data source=(local);user id=sa; password = sa;initial catalog=cjg";
                myconn = new SqlConnection(strConnection);
                if(shipname1!=""&&companyname1!=""&&portofregistry1!=""&&peccancytime1!=""&&peccancyplace1!=""&&peccancyreason1!=""&&TextBox6.Text!="")
                {
               
                    myconn.Open();
                    string insertstr = "insert into [peccancy](shipname,companyname,portofregistry,peccancytime,peccancyplace,peccancyreason,peccancymoney,pk) values ('"+shipname1+"','"+companyname1+"','"+portofregistry1+"','"+peccancytime1+"','"+peccancyplace1+"','"+peccancyreason1+"','"+@peccancymoney1+"','"+pk+"')";
                    SqlCommand cmd = new SqlCommand(insertstr,myconn);
                    cmd.Parameters.Add("@peccancymoney1",peccancymoney1);
                    cmd.ExecuteNonQuery();                       
                    //关闭连接
                    myconn.Close();
           

                    //
                    Response.Write("<script language=javascript>alert('保存成功!')</script>") ;
                    this.BindData();
                    //
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    TextBox3.Text = "";
                    TextBox4.Text = "";
                    TextBox5.Text = "";
                    TextBox6.Text = "";
                    this.Text1.Value = "";
                    //this.TextBox8.Text = "";
                    //TextBox7.Text = "";
                    //TextBox10.Text = "";
                }
               
                else
                {
                    Response.Write("<script language=javascript>alert('请填满所有项!')</script>") ;
                }
            }   
            catch(Exception ex)
            {
                throw ex;
            }
这段程序报“/WebApplication1”应用程序中的服务器错误。
--------------------------------------------------------------------------------
不允许从数据类型 varchar 到数据类型 money 的隐性转换(表 'cjg.dbo.peccancy',列 'peccancymoney')。请使用 CONVERT 函数来运行此查询。
这样的错误,该如何解决?
搜索更多相关主题的帖子: money varchar 
2009-08-31 15:45
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:14 
请使用 CONVERT 函数,不是已经告诉你了嘛

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-08-31 16:25
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
请使用 CONVERT 函数,不是已经告诉你了嘛

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-08-31 16:25
快速回复:varchar到money的转换?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025316 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved