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
相关文档:
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">路径+文件 ......
1:先对一些概念的理解:
JDBC:Java DataBase Connection
本季目标
1、JDBC的分类
2、JDBC的主要操作类和接口:
DriverManager、Connection、Statement、PreparedStatement、ResultSet
3、如何使用JDBC连接MySQL数据库
www.mldn.cn上有MYSQL的教程。
1、什么是JDBC?
JDBC是JAVA提供的一个服务,专门用于访问 ......
public static class AccessHelper
{
//数据库连接字符串
//WebForm
//public static readonly string conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Request.PhysicalApplicationPath + System.Configuration.ConfigurationManager ......
DB2ConnectionString
b2str = "Provider=MSDASQL.1;Password=a$sk6G7;Persist Security Info=True;User ID=DBA;Data Source=ConDB2SFXXK"
AccessConnectonString
accessstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DMSJK.mdb;Jet OLEDB:database password=" ......