放假在家实在无聊没事干写的小项目
舔狗日记是通过查询数据库实现的,表内容已经上传了,可以自己更改增加
表数据下载地址
public int getRandom() {
//获得随机数
int Max = 0;
Random r = new Random();
MySqlConnection con = DBhelper.getConnection();
string sql = "select count(*) from tab_diary ";//获取到数据库中总记录的数量
MySqlCommand com = new MySqlCommand(sql, con);
MySqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Max = Convert.ToInt32(dr["count(*)"]);
}
int order= r.Next(0, Max);//通过获取到的总记录数量生成一个0-总数量的随机数便于调用查询
return order;
DBhelper.close(con);
}
public void getContent(int number) {
//通过获得的随机数获取数据库中内容
MySqlConnection con = DBhelper.getConnection(