本帖最后由 陈育梅 于 2012-11-1 10:45 编辑
- using (SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select count(*) from User_T where Username=@name ";
- cmd.Parameters.Add(new SqlParameter("name", txtusername.Text));
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- if (reader.Read())
- {
- int errortime = reader.GetInt32(reader.GetOrdinal("Errortime"));
- if (errortime > 3)
- {
- MessageBox.Show("登录次数过多,禁止登录!");
- return;
- }
- string dbpassword = reader.GetString(reader.GetOrdinal("Password"));
- if (dbpassword == txtpassword.Text)
- {
- MessageBox.Show("登录成功");
- }
- else
- {
- IneErrortime();
- MessageBox.Show("登录失败");
- }
- }
- else
- {
- MessageBox.Show("用户名不存在");
- }
- }
- }
复制代码 运行时提示:Errortime 确保列表中最大索引小于列表大小!求指点,谢谢
|