我一直在阅读有关SQL注入的内容,我想确保我的代码可以说是"安全",我打算使用RegExp验证器来检查用户输入,但是这里的另一个帖子建议只使用参数化查询,我我正在使用它们,但我想确保我的代码是安全的,是吗?
using ( SqlConnection dataConnection = new SqlConnection(myConnectionString) )
{
using ( SqlCommand dataCommand = dataConnection.CreateCommand() )
{
dataCommand.CommandText = "INSERT INTO Lines (Name, CreationTime) " +
"VALUES (@LineName, @CurrentDateTime)";
dataCommand.Parameters.AddWithValue("@LineName", TextBox2.Text);
dataCommand.Parameters.AddWithValue("@CurrentDateTime", DateTime.Now.ToString());
dataConnection.Open();
//do other DB stuff
Run Code Online (Sandbox Code Playgroud)
我打破了最后一部分以使帖子更短,其余部分只是尝试捕获异常并关闭数据库连接以及提供用户关于插入成功的反馈.
我不是很好的机智JS和我只是不明白为什么这不会工作!代码使用jquery将脉动效应应用于我的一个div并永远运行,除非我用另一个函数停止它,但我无法弄清楚为什么我的第一段代码不会运行!
function animate(var x){
// Do pulsate animation
$(x).effect("pulsate", { times:4 }, 5000);
// set timeout and recall after 10secs
setTimeout(animate, 10000);
}
$(document).ready(animate("#mydiv"));
Run Code Online (Sandbox Code Playgroud)
让它工作的唯一方法是让我这样做
function animate(){
// Do pulsate animation
$("#mydiv").effect("pulsate", { times:4 }, 5000);
// set timeout and recall after 10secs
setTimeout(animate, 10000);
}
$(document).ready(animate);
Run Code Online (Sandbox Code Playgroud)
请注意,在第一个代码段中,代码使用变量更有用,第二个代码使用硬编码的选择器名称