终于到周末了,传智播客.Net培训—ADO.NetADO.NET 视频教程,从1看到9,因为以前有一点基础,所以听起来,不是很吃力,但是感觉很多,对SQL注入也有的深刻的理解。
同时也通过视频,知道了一个很有用的软件:Reflector (Reflector是由微软员工Lutz Roeder编写的免费程序。Reflector的出现使.NET程序员眼前豁然开朗,因为这个免费工具可以将.NET程序集中的中间语言反编译成C#或者Visual Basic代码) 太好了。百度搜索,下下来,果然好用,哈哈哈,
下边就帖一下我写的登陆练习代码:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
-
- namespace 登录练习1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string connStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDb.mdf;Integrated Security=True;User Instance=True";
- private void Form1_Load(object sender, EventArgs e)
- {
-
- }
- private void updateErrorTimes(int n)
- {
- using (SqlConnection conn = new SqlConnection(connStr))
- {
- conn.Open();
- using (SqlCommand cmd = conn.CreateCommand())
- {
- string sql="";
- if (n==1)
- {
- sql="update T_Users set ErrorTimes=ErrorTimes+1 where username=@uname";
- }else if (n==0){
- sql="update T_Users set ErrorTimes=0 where username=@uname";
- }
- cmd.CommandText = sql;
- cmd.Parameters.Add(new SqlParameter("uname",textName.Text));
- cmd.ExecuteNonQuery();
- }
- }
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- using (SqlConnection conn = new SqlConnection(connStr))
- {
- conn.Open();
- using(SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select * from T_Users where username=@uname";
- cmd.Parameters.Add(new SqlParameter("uname",textName.Text));
- SqlDataReader reader = cmd.ExecuteReader();
- if (reader.Read())
- {
- int errTimes = reader.GetInt32(reader.GetOrdinal("ErrorTimes"));
- if (errTimes >= 3)
- {
- MessageBox.Show("登陆次数过多,禁止登陆.");
- return;
- }
- else {
- string password = reader.GetString(reader.GetOrdinal("password"));
- if (password == textPassword.Text)
- {
- MessageBox.Show("登录成功");
- //登录错误次数改为0
- }
- else {
- MessageBox.Show("登录失败!");
- //登录错误次数加1
- updateErrorTimes(1);
- }
- }
- }
- else
- {
- MessageBox.Show("用户名不存在.");
- }
-
- }
- }
- }
-
- }
- }
复制代码 |