日期:2014-05-17 浏览次数:20525 次
protected void Button1_Click(object sender, EventArgs e)
{
// 得到输入的次数
int num = int.Parse(this.txNum.Text.Trim());
//得到毫秒数
int time1 = DateTime.Now.Millisecond;
//将时间显示在页面上 格式为:yy-mm-dd hh:mm:ss:mm显示到毫秒数
this.lbltime1.Text = DateTime.Now + ":" + time1.ToString();
for (int i = 0; i < num; i++)
{
user user1 = new user();
Random rd = new Random();
user1.Name = Createname(rd.Next(6, 10));
user1.Pwd = Createname(rd.Next(8, 16));
user1.Qq = Createqq(rd.Next(5, 10));
user1.Time = DateTime.Now;
reg(user1);
}
int time2 = DateTime.Now.Millisecond;
this.lbltime2.Text = DateTime.Now + ":" + time2.ToString();
}
private void reg(user user)
{
string strconn = "server=.;database=autoreg;uid=sa;pwd=sa2005";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sql = "insert into users values (@name,@pwd,@QQ,@time)";
SqlParameter[] parm = new SqlParameter[]
{
new SqlParameter("@name",user.Name),
new SqlParameter("@pwd",user.Pwd),
new SqlParameter("@QQ",user.Qq),
new SqlParameter("@time",user.Time)
};
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(parm);
int newid = cmd.ExecuteNonQuery();
conn.Close();
}
private string Createname(int num)