栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

有什么好的方法可以防止SQL注入?[重复]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

有什么好的方法可以防止SQL注入?[重复]

通过使用

SqlCommand
及其子参数集,您无需承担所有检查sql注入的麻烦,这些麻烦将由这些类处理。

这是一个示例,摘自以上文章之一:

private static void UpdateDemographics(Int32 customerID,    string demoXml, string connectionString){    // Update the demographics for a store, which is stored      // in an xml column.      string commandText = "UPDATE Sales.Store SET Demographics = @demographics "        + "WHERe CustomerID = @ID;";    using (SqlConnection connection = new SqlConnection(connectionString))    {        SqlCommand command = new SqlCommand(commandText, connection);        command.Parameters.Add("@ID", SqlDbType.Int);        command.Parameters["@ID"].Value = customerID;        // Use AddWithValue to assign Demographics.         // SQL Server will implicitly convert strings into XML.        command.Parameters.AddWithValue("@demographics", demoXml);        try        { connection.Open(); Int32 rowsAffected = command.ExecuteNonQuery(); Console.WriteLine("RowsAffected: {0}", rowsAffected);        }        catch (Exception ex)        { Console.WriteLine(ex.Message);        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/576332.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号