/// <summary> /// 获取查询结果的条目数量 /// </summary> /// <param name="sql"></param> /// <param name="values"></param> /// <returns></returns> public static int getResultCount(string sql, params SqlParameter[] values) { reader = DBHelper.GetReader(sql, values); int i = 0; while (reader.Read()) { i++; } DBHelper.ColseReader(); return(i); }
/// <summary> /// 返回用户名密码符合要求的个数 /// </summary> /// <param name="user"></param> /// <returns></returns> public static int selUser(User user) { string sql = "select * from [User] where [User_Name] = @User_Name and [User_Pwd] = @User_Pwd"; SqlParameter[] values = new SqlParameter[] { new SqlParameter("@User_Name", user.User_Name), new SqlParameter("@User_Pwd", user.User_Pwd) }; int i = DBHelper.getResultCount(sql, values); DBHelper.ColseReader(); return(i); }
/// <summary> /// 根据用户的名字获取用户的所有信息,保存在User类中,返回至调用者,如果没有查到返回null /// </summary> /// <param name="_user_Name"></param> /// <returns></returns> public static User getUser(string _user_Name) { User user = new User(); string sql = "select * from [User] where [User_Name] ='" + _user_Name + "'"; SqlDataReader reader = DBHelper.GetReader(sql); while (reader.Read()) { user.User_Id = (int)reader["User_Id"]; user.User_Name = (string)reader["User_Name"]; user.User_Pwd = (string)reader["User_Pwd"]; user.User_Admin = (int)reader["User_Admin"]; } DBHelper.ColseReader(); return(user); }
/// <summary> /// 插入一条用户数据,返回所影响的行数 /// </summary> /// <param name="_user"></param> /// <returns></returns> public static int addUser(User _user) { string sql = "insert into [User]([User_Name],[User_Pwd],[User_Admin])" + "values(@User_Name,@User_Pwd,@User_Admin)"; SqlParameter[] values = new SqlParameter[] { new SqlParameter("@User_Name", _user.User_Name), new SqlParameter("@User_Pwd", _user.User_Pwd), new SqlParameter("@User_Admin", _user.User_Admin) }; int i = DBHelper.ExecuteCommand(sql, values); DBHelper.ColseReader(); return(i); }
/// <summary> /// 根据新闻的Id获取新闻类 /// </summary> /// <param name="_newId"></param> /// <returns></returns> public static New getNew(int _newId) { New news = new MDL.New(); string sql = "select * from [New] where [New_Id]='" + _newId + "'"; SqlDataReader reader = DBHelper.GetReader(sql); while (reader.Read()) { news.Create_Time = (DateTime)reader["Create_Time"]; news.Is_Show = (int)reader["Is_Show"]; news.New_Content = (string)reader["New_Content"]; news.New_Id = _newId; news.New_Image = (string)reader["New_Image"]; news.New_Title = (string)reader["New_Title"]; news.New_Type_Id = (int)reader["New_Type_Id"]; } DBHelper.ColseReader(); return(news); }
/// <summary> ///查询最大New_Id的第_order个的新闻类型为_newType 的New类 /// </summary> /// <param name="_order"></param> /// <param name="_newType"></param> /// <returns></returns> public static New selNewOrder(int _order, int _newType) { New news = new New(); string sql = "select * from New where New_Type_Id='" + _newType + "' Order By New_Id desc"; SqlDataReader reader = DBHelper.GetReader(sql); for (int i = 0; i < _order; i++) { reader.Read(); } news.Create_Time = (DateTime)reader["Create_Time"]; news.Is_Show = (int)reader["Is_Show"]; news.New_Content = (string)reader["New_Content"]; news.New_Id = (int)reader["New_Id"]; news.New_Image = (string)reader["New_Image"]; news.New_Title = (string)reader["New_Title"]; news.New_Type_Id = (int)reader["New_Type_Id"]; DBHelper.ColseReader(); return(news); }