Exemple #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebApi_Model.Customers model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Customers(");
            strSql.Append("CustomerName,Tel)");
            strSql.Append(" values (");
            strSql.Append("@CustomerName,@Tel)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50),
                new SqlParameter("@Tel",          SqlDbType.VarChar, 20)
            };
            parameters[0].Value = model.CustomerName;
            parameters[1].Value = model.Tel;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebApi_Model.Customers model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Customers set ");
            strSql.Append("CustomerName=@CustomerName,");
            strSql.Append("Tel=@Tel");
            strSql.Append(" where Kid=@Kid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50),
                new SqlParameter("@Tel",          SqlDbType.VarChar,  20),
                new SqlParameter("@Kid",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CustomerName;
            parameters[1].Value = model.Tel;
            parameters[2].Value = model.Kid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebApi_Model.Customers GetModel(int Kid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Kid,CustomerName,Tel from Customers ");
            strSql.Append(" where Kid=@Kid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Kid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Kid;

            WebApi_Model.Customers model = new WebApi_Model.Customers();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Kid"] != null && ds.Tables[0].Rows[0]["Kid"].ToString() != "")
                {
                    model.Kid = int.Parse(ds.Tables[0].Rows[0]["Kid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomerName"] != null && ds.Tables[0].Rows[0]["CustomerName"].ToString() != "")
                {
                    model.CustomerName = ds.Tables[0].Rows[0]["CustomerName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Tel"] != null && ds.Tables[0].Rows[0]["Tel"].ToString() != "")
                {
                    model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }