Parameter Queries in ASP.NET with MS Access
Parameter Queries in ASP.NET with MS Access
A selection of code samples for executing queries against MS Access using parameters.
Making use of the ASP.NET 2.0 datasource controls is fine, but it is important to understand how to manually create data access code. Best practice dictates that, at the very least, parameters are used to represent values that are passed into the SQL to be executed, rather than un-sanitised values straight from the user. The main reason for this cannot be over-emphasised in terms of its importance - it protects the application against SQL Injection attacks. In addition, parameters do not require delimiters. Therefore there is no need to worry about octothorpes (#) or apostrophes for dates, or doubling single quotes in strings.
These samples all assume that the values being passed into the parameters have been properly validated for datatype, existence, range etc, according to the business rules for the application. The serverside validation code is not included, as it will differ from app to app, and is not the focus of these samples anyway. However, it is important to stress that all user input must be validated server-side before being included in a SQL statement. Better to reject it outright, rather than have to unpick rubbish that pollutes the database...
The required components are an OleDbConnection object, a ConnectionString property, an OleDbCommand object and an OleDbParameterCollection. These all reside in the System.Data.OleDb namespace, which needs to be referenced. Also, the connection string is held in the Web.Config, and a static method GetConnString() has been created in a class called Utils (also static) to retrieve it:
[C#]
public static string GetConnString()
{
return WebConfigurationManager.ConnectionStrings["myConnStr"].ConnectionString;
}
[VB]
Public Shared Function GetConnString() As String
Return WebConfigurationManager.ConnectionStrings("myConnStr").ConnectionString
End Function
Fo
相关文档:
本文介绍通过缓存来提高网页的执行效率。
1. ASP.NET Output Caching
当一个网页频繁被访问的时候,我们可以通过把整个网页缓存来提高执行效率。这样作的优点是,当用户再次访问这个网页的时候,被格式化好的HTML会被直接送显。
为什么会存在这种效果呢?我们通过ASP.NET的基本运行机制来解释� ......
在不支持Cookies的移动设备模拟器中无法正常进行表单验证,联想到昨天使用web.config设置cookieless属性时会在访问时会出现"Cannot use a leading .. to exit above the top directory"的异常,自然而然的我就想到了前一段时间困扰我很久的一个站点异常无法使用前导 .. 在顶级目录上退出(Cannot use a leading .. to exit abo ......
using System;
using System.Text;
using System.Web;
using System.IO;
namespace Chsword {
/// <summary>
/// 成幻互联缓存类
/// 邹健 2007.5
/// ......
一. 使用QueryString变量
QueryString是一种非常简单也是使用比较多的一种传值方式,但是它将传递的值显示在浏览器的地址栏中,如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法。
Response.Redirect( "target.aspx?param1=hello& ......
Asp.net控件(包括Web服务器控件和Html服务器控件)都没有双击事件,那么该如何将双击事件付给Asp.Net控件呢?我们以Lable控件为例。
一、首先加入控件,ID为Lable1,然后加入一个Button控件,ID为Button1,代码如下
& ......