首页 新闻 会员 周边 捐助

sqlparamter与Unicode

0
悬赏园豆:5 [已解决问题] 解决于 2013-03-06 11:15
 insert into tbNewWordInfo values('university',N'ˌjuːnɪˈvɜː(r)səti'')
请教下这个sql插入语句怎样用sqlparameter来写参数? 
直接用sql语句插入不会乱码,但是用sqlParameter怎样来写?
天蓝若空的主页 天蓝若空 | 初学一级 | 园豆:9
提问于:2013-03-02 15:19
< >
分享
最佳答案
0

 #region private
        private int iD;
        private int projectID;
        private string category;
        private decimal unitPrice;
        #endregion
        #region public
        public int ID
        {
            get { return iD; }
            set { iD = value; }
        }

        public int ProjectID
        {
            get { return projectID; }
            set { projectID = value; }
        }

        public string Category
        {
            get { return category; }
            set { category = value; }
        }

        public decimal UnitPrice
        {
            get { return unitPrice; }
            set { unitPrice = value; }
        }

        #endregion

        /// <summary>
        /// 添加ys
        /// </summary>
        /// <param name="steelUintPrice">ys</param>
        /// <returns>最新编号</returns>
        public int Add()
        {
            string sql = @"INSERT INTO SteelUintPrice(ProjectID,Category,UnitPrice)
     values(@ProjectID,@Category,@UnitPrice);
     SELECT SCOPE_IDENTITY();";

            SqlParameter[] para = new SqlParameter[]
    {
     new SqlParameter("@ProjectID",SqlDbType.Int,4),
     new SqlParameter("@Category",SqlDbType.NVarChar,50),
     new SqlParameter("@UnitPrice",SqlDbType.Decimal,9)
    };
            int i = 0;
            para[i++].Value = ProjectID;
            para[i++].Value = Category;
            para[i++].Value = UnitPrice;

            return Convert.ToInt32(DbHelperSQL.GetSingle(sql, para));
        }

收获园豆:5
happydaily | 菜鸟二级 |园豆:260 | 2013-03-02 18:15

非常感谢重点就在new SqlParameter("@Category",SqlDbType.NVarChar,50) 用Nvarchar之后可以存特殊字符。

天蓝若空 | 园豆:9 (初学一级) | 2013-03-06 11:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册