<< Chapter < Page Chapter >> Page >

Khi đối tượng rdoResultset được tạo ra, ta có thể di chuyển đến mẩu tin xác định bằng các phương thức MoveFirst, MoveLast, MoveNext, MovePrevious.

Đối tượng rdotable

Đối tượng này xác định một bảng trong một nguồn dữ liệu ODBC. Đối tượng này không được sử dụng cho các thao tác truy xuất dữ liệu mà nó chỉ được sử dụng khi ta cần xác định cấu trúc các bảng của cơ sở dữ liệu của ta.

Đối tượng rdoparameter

Đối tượng này xác định các tham số đầu vào hay các kết quả nhận được từ các thủ tục lưu trữ sẵn trong cơ sở dữ liệu.

Sử dụng rdo trong chương trình

Thiết lập kết nối đến nguồn dữ liệu

  • Trước tiên ta phải tham chiếu đến mô hình đối tượng RDO.
  • Nối kết đến nguồn dữ liệu nhờ đối tượng rdoConnection.

- Khai báo một biến đối tượng rdoConnection.

- Khởi tao đối tượng, sau đó thiết lập các thuộc tính và các phương thức thích hợp để hoàn tất kết nối; trong đó có hai thuộc tính cần quan tâm là chuỗi kết nối (ConnectionString) và loại con trỏ (Cursor Driver).

  • Thiết lập nối kết nhờ phương thức EstablishConnection của đối tượng rdoConnection.

Chuỗi kết nối (odbc connect string)

Chuỗi kết nối được sử dụng khi thiết lập nối kết đến nguồn dữ liệu. Đây là một chuỗi (String) xác định các thông tin quan trọng gởi đến trình điều khiển ODBC để truy cập dữ liệu. Các thông tin cần quan tâm: tên nguồn dữ liệu (DSN Name), User ID, Password.

Các tham số của chuỗi kết nối ODBC:

Tham số Ý nghĩa
DSN Tên nguồn dữ liệu ODBC
UID Tên người dùng cơ sở dữ liệu
PWD Mật khẩu truy cập
DRIVER Trình điều khiển DBC
DATABASE Tên của cơ sở dữ liệu được nối kết
SERVER Tên máy chứa cơ sở dữ liệu phục vụ (database server)
WSID Tên máy chứa cơ sở dữ liệu khách (database client)
APP Tên của tập tin chương trình (*.exe)

Chuỗi kết nối được xác lập nhờ thuộc tính Connect của đối tượng rdoConnection.

Ví dụ: Chuỗi nối kết đến 1 DSN của cơ sở dữ liệu Access Biblio:

Set m_Connection = New RDO.rdoConnection

m_Connection.Connect = "DSN=Biblo"

m_Connection.EstablishConnection

Chuỗi nối kết đến DSN Publications của cơ sở dữ liệu SQL Server:

Set m_Connection = New RDO.rdoConnection

m_Connection.Connect = "DSN=Biblo;UID=sa;PWD=;"

m_Connection.EstablishConnection

Bên cạnh nối kết chuẩn thông qua ODBC, RDO cũng hỗ trợ loại nối kết DSN cấp thấp (DSN-less connection). Đối với loại này, ta không cần định nghĩa tên nguồn dữ liệu (DSN) trong bộ quản trị ODBC của Windows. Lúc này tất cả các thông tin về cơ sở dữ liệu được cung cấp đầy đủ trong chuỗi nối kết.

Ví dụ: Chuỗi nối kết cấp thấp đến cơ sở dữ liệu SQL Server Pubs:

Set m_Connection = New RDO.rdoConnection

m_Connection.Connect ="DRIVER={SQL Server};”&_

“SERVER=(local);DATABASE=Pubs;UID=admin;PWD=;DSN=;"

m_Connection.EstablishConnection

Trình điều khiển con trỏ (cursor drivers)

Trình điều khiển con trỏ xác định cách thức tập các mẩu tin trả về từ cơ sở dữ liệu được lưu trữ như thế nào, có thể chúng được lưu trữ tại máy chủ (server) hay máy trạm (client).

Trình điều khiển con trỏ được thiết lập nhờ thuộc tính CursorDriver của đối tượng Connection (trước khi gọi thực thi phương thức EstablishConnection) và các giá trị sau có thể đề cử cho nó:

Giá trị Ý nghĩa
rdUseIfNeeded Trình điều khiển ODBC tự động xác định loại con trỏ (được lưu phía server hay client). Nếu có thể, con trỏ loại được lưu phía server được đề cử.
rdUseODBC Xác định loại con trỏ của ODBC chuẩn, nghĩa là tập tất cả các mẩu tin được lưu ở máy client.
rdUseServer Tập các mẩu tin được lưu phia server. Tuy nhiên loại con trỏ này không thích hợp lắm trong môi trường đa người dùng.
rdUseClientBatch Giống như rdUseODBC nhưng có thể được cập nhật đồng thời.
rdUseNone Không sử dụng con trỏ, tập các mẩu tin được trả về một lần duy nhất lúc chúng được yêu cầu. Ta chỉ có thể di chuyển tới trong tập các mẩu tin kết quả.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Giáo trình visual basic. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10777/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Giáo trình visual basic' conversation and receive update notifications?

Ask