Esempio n. 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tbMessage GetModelTran(int id, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, messagetitle, messagecontent, createtime, userid, visitcount  ");
            strSql.Append("  from tbMessage ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Util.MyUtil.PrintSql(strSql.ToString());
            Model.tbMessage model = new Model.tbMessage();
            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.messagetitle   = ds.Tables[0].Rows[0]["messagetitle"].ToString();
                model.messagecontent = ds.Tables[0].Rows[0]["messagecontent"].ToString();
                if (ds.Tables[0].Rows[0]["createtime"].ToString() != "")
                {
                    model.createtime = DateTime.Parse(ds.Tables[0].Rows[0]["createtime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userid"].ToString() != "")
                {
                    model.userid = int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["visitcount"].ToString() != "")
                {
                    model.visitcount = int.Parse(ds.Tables[0].Rows[0]["visitcount"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tbMessage model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbMessage set ");

            strSql.Append(" messagetitle = @messagetitle , ");
            strSql.Append(" messagecontent = @messagecontent , ");
            strSql.Append(" createtime = @createtime , ");
            strSql.Append(" userid = @userid , ");
            strSql.Append(" visitcount = @visitcount  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",             SqlDbType.Int,            4),
                new SqlParameter("@messagetitle",   SqlDbType.NVarChar,      50),
                new SqlParameter("@messagecontent", SqlDbType.Text,      999999),
                new SqlParameter("@createtime",     SqlDbType.DateTime),
                new SqlParameter("@userid",         SqlDbType.Int,            4),
                new SqlParameter("@visitcount",     SqlDbType.Int, 4)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.messagetitle;
            parameters[2].Value = model.messagecontent;
            parameters[3].Value = model.createtime;
            parameters[4].Value = model.userid;
            parameters[5].Value = model.visitcount;                       Util.MyUtil.PrintSql(strSql.ToString());
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddTran(Model.tbMessage model, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbMessage(");
            strSql.Append("messagetitle,messagecontent,createtime,userid,visitcount");
            strSql.Append(") values (");
            strSql.Append("@messagetitle,@messagecontent,@createtime,@userid,@visitcount");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@messagetitle",   SqlDbType.NVarChar,    50),
                new SqlParameter("@messagecontent", SqlDbType.NVarChar,  3000),
                new SqlParameter("@createtime",     SqlDbType.DateTime),
                new SqlParameter("@userid",         SqlDbType.Int,          4),
                new SqlParameter("@visitcount",     SqlDbType.Int, 4)
            };

            parameters[0].Value = model.messagetitle;
            parameters[1].Value = model.messagecontent;
            parameters[2].Value = model.createtime;
            parameters[3].Value = model.userid;
            parameters[4].Value = model.visitcount;

            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());
        }
Esempio n. 4
0
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.tbMessage GetModelTran(int id ,SqlTransaction transaction)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id, messagetitle, messagecontent, createtime, userid, visitcount  ");			
			strSql.Append("  from tbMessage ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			 Util.MyUtil.PrintSql(strSql.ToString());
			Model.tbMessage model=new Model.tbMessage();
			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.messagetitle= ds.Tables[0].Rows[0]["messagetitle"].ToString();
																																model.messagecontent= ds.Tables[0].Rows[0]["messagecontent"].ToString();
																												if(ds.Tables[0].Rows[0]["createtime"].ToString()!="")
				{
					model.createtime=DateTime.Parse(ds.Tables[0].Rows[0]["createtime"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["userid"].ToString()!="")
				{
					model.userid=int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["visitcount"].ToString()!="")
				{
					model.visitcount=int.Parse(ds.Tables[0].Rows[0]["visitcount"].ToString());
				}
																														
				return model;
			}
			else
			{
				return null;
			}
		}