ACCESS的存储过程创建与执行创建
ACCESS的存储过程创建与执行
创建:
在Access自身的帮助中看到了Create Procedure语句。
测试了老半天,终于发现了诀窍:
必须使用OleDb连接才能使用Create Procedure语句。
ODBC连接不支持该语句,提示Create Table语法错误。
创建了存储过程后,使用Office Access工具打开数据库,在“对象 - 查询”中能够看到你创建的存储过程。
创建存储过程的语法:
CODE
Create Procedure YourProc
(
@param1 varchar(254),
@param2 int
)
As
(
select * from Table1 where ID>@param2 and username=@param1
)
查询数据时只需要使用:
Rs.Open "YourProc 参数1,参数2,参数3", Conn
或者
Conn.Execute("exec YourProc 参数1,参数2,参数3")
第二个例子:
直接在库里创建,参考:
//**************************************************************
// Stored Procedure ListBySubject_Sample
// CREATE procedure ListBySubject_Sample
// (
// @SubjectID Integer
// )
// AS
// SELECT top 5 BookID, BookTitle, Author, Price, Retail
// from Products
// where SubjectID = @SubjectID
// RETURN
//
// GO
//**************************************************************
SqlDataReader GetSpecials_Procedure(SqlConnection currentConnection)
{
SqlDataReader myDataReader;
Object my_DBNull;
try {
my_DBNull = Convert.DBNull;
SqlDataReader myReader;
int subjectidin = 21;
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = currentConnection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "LISTBYSUBJECT_SAMPLE";
myCommand.Parameters.Add(new SqlParameter("@SubjectID",
SqlDbType.Int, 4, ParameterDirection.Input,
在Access自身的帮助中看到了Create Procedure语句。
测试了老半天,终于发现了诀窍:
必须使用OleDb连接才能使用Create Procedure语句。
ODBC连接不支持该语句,提示Create Table语法错误。
创建了存储过程后,使用Office Access工具打开数据库,在“对象 - 查询”中能够看到你创建的存储过程。
创建存储过程的语法:
CODE
相关文档:
ASP+Access数据库的18条安全法则:
1.首先,我们需要过滤所有客户端提交的内容,其中包括?id=N一类,另外还有提交的html代码中的操作数据库的select及asp文件操作语法,大家可以把提交的字符转义,然后再存入数据库。
2.然后需要对访问Access数据库的页面进行授权,针对显示数据页面只能使用select语句,过滤其他的update,asp ......
1.创建 Access 数据库,并关闭其连接
Access 操作的两个引用:
1) Microsoft ActiveX Data Objects 2.8 Library
2) Microsoft ADO Ext. 2.8 for DDL and Security
/// <summary>
/// 创建数据库并返回连接字符串
/// </summary>
/// <param name="dbName">路径+文件 ......
有三种办法
第一种是用access的JDBC驱动程序,到http://industry.java.sun.com/products/jdbc/drivers这个网站上查找并下在access的jdbc驱动程序。
第二个办法是你用下面的代码试试
con = DriverManager.getConnection("jdbc:odbc:Dri ......
using System;
using System.IO;
using System.Windows.Forms;
using Access = Microsoft.Office.Interop.Access;
// 添加引用->.NET-> dao,Microsoft.Office.Interop.Access
namespace WinFormAccess
{
public partial class FormAccess : Form
{
&nbs ......