首先解释下什么是SQL注入,就是hacker在进行网扎攻击的时候这是最常用的手段,我这是看了网站入侵与脚本攻防修炼后的第一个例子,我做的是入侵自己的ASP.NET+SQL 

SERVER,只是在登录的过程中,对数据库中的一个表进行删除操作,现在这是C#的代码


//这是登录过程代码
string link_str = @"Data Source=...-PC;Initial Catalog=inventiontool数据库;Integrated Security=True";
            SqlConnection con = new SqlConnection(link_str);
            try
            {
                con.Open();
            }
            catch(Exception ew)
            {
                int b = 0;
                b++;
            }
            string uname = LoginUser.UserName.ToString();            
            string pwd = LoginUser.Password.ToString();
            string str_cmd = "select* from heh where id='"+uname+"' and sha='"+pwd+"'";
            SqlCommand cmd = new SqlCommand(str_cmd, con);
         //  int a= cmd.ExecuteNonQuery();
       //     SqlDataReader reader= cmd.ExecuteReader();
           if (reader.Read())
           {
               int a = 0;
               a++;
           }            
            con.Close();


用户名的控件是UserName,密码的控件是Password,我们的代码中对于用户输入的参数没有进行任何的检测,这就导致了可能会产生SQL注入的风险,现在试下我们在

UserName中输入sdadda(这是随便写的)

Password中输入sda';drop table heh;--

即可,我们就把这个表heh删除了,这就是SQL注入的典型应用。经过测试,SqlCommand的ExecuteNonQuery或者ExecuteReader方法都能实现表的删除

--就是单行注释

其实SQL注入的主要思想就是精心打造自己的SQL语句,使得该语句实现hacker想要的功能