Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tbSubject model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbSubject set ");

            strSql.Append(" subjectname = @subjectname  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",          SqlDbType.Int,      4),
                new SqlParameter("@subjectname", SqlDbType.NVarChar, 50)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.subjectname;                       Util.MyUtil.PrintSql(strSql.ToString());
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.tbSubject model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbSubject(");
            strSql.Append("subjectname");
            strSql.Append(") values (");
            strSql.Append("@subjectname");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@subjectname", SqlDbType.NVarChar, 50)
            };

            parameters[0].Value = model.subjectname;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
            Util.MyUtil.PrintSql(strSql.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tbSubject GetModelTran(int id, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, subjectname  ");
            strSql.Append("  from tbSubject ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Util.MyUtil.PrintSql(strSql.ToString());
            Model.tbSubject model = new Model.tbSubject();
            DataSet         ds    = SQLHelper.ExecuteDataset(transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.subjectname = ds.Tables[0].Rows[0]["subjectname"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddTran(Model.tbSubject model, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbSubject(");
            strSql.Append("subjectname");
            strSql.Append(") values (");
            strSql.Append("@subjectname");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@subjectname", SqlDbType.NVarChar, 50)
            };

            parameters[0].Value = model.subjectname;

            object obj = SQLHelper.ExecuteScalar(transaction, CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
            Util.MyUtil.PrintSql(strSql.ToString());
        }
Ejemplo n.º 5
0
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.tbSubject GetModelTran(int id ,SqlTransaction transaction)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id, subjectname  ");			
			strSql.Append("  from tbSubject ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			 Util.MyUtil.PrintSql(strSql.ToString());
			Model.tbSubject model=new Model.tbSubject();
			DataSet ds=SQLHelper.ExecuteDataset(transaction,CommandType.Text, strSql.ToString(), parameters);
			
			if(ds.Tables[0].Rows.Count>0)
			{
												if(ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
																																				model.subjectname= ds.Tables[0].Rows[0]["subjectname"].ToString();
																										
				return model;
			}
			else
			{
				return null;
			}
		}