日期:2014-05-17  浏览次数:20907 次

sql模糊查询为什么返回时空值?? 急急急!!
 public List<Notice> GetAllLike(string title)
        {
            //string sql = "select  * from notice where notice.NoticeTitle like '%" + title + "% 'order by notice.PostDate desc  ";

            string sql = "select * from notice where notice.NoticeTitle like '%@NoticeTitle%' order by notice.PostDate desc ";
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlParameter par = new SqlParameter("@NoticeTitle", title);
            comm.Parameters.Add(par);
            SqlDataReader reader = comm.ExecuteReader();
            List<Notice> list = new List<Notice>();
            try
            {
                while (reader.Read())
                {
                    Notice notice = new Notice();
                    notice.Id = Convert.ToInt32(reader["Id"]);
                    notice.NoticeTitle = reader["NoticeTitle"].ToString();
                    notice.NoticeContent = reader["NoticeContent"].ToString();
                    notice.PostName = reader["PostName"].ToString();
                    notice.PostTime = Convert.ToDateTime(reader["PostDate"]);
                    notice.NoticeDepartment = reader["NoticeDepartment"].ToString();
                    list.Add(notice);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
   &nbs