net防止sql注入的方法:
在直接處理SQL語句時,將傳遞的值進行參數化,然后在進行賦值,例如:
cmd.CommandText = @"select count(*) from UserInfo where UserName=@UserName and UserPwd=@UserPwd";
cmd.Parameters.AddWithValue("@UserName",txtUserName.Text); //SQL參數化
cmd.Parameters.AddWithValue("@UserPwd",txtUserPwd.Text);
object result = cmd.ExecuteScalar();