<< Chapter < Page Chapter >> Page >
  • Chọn loại CSDL mà ta muốn thao tác (Access, Foxpro, SQL Server,…), nhấn Finish. Sau khi nhấn Finish, một màn hình sẽ hiện ra cho phép ta nhập vào Data Source Name, đây là tên của kết nối CSDL. Tên của kết nối không cần phải giống với tên của cơ sở dữ liệu. Phần Description dùng để gõ các thông tin mô tả về kết nối. Ngoài ra ta còn phải chọn đường dẫn đến tập tin CSDL tương ứng.

Truy cập nguồn dữ liệu với điều khiển dao data và odbc direct

DAO tự động nạp bộ máy cơ sở dữ liệu Jet mỗi khi nó truy cập dữ liệu Client/Server, thậm chí khi ta không thực sự sử dụng cơ sở dữ liêu Jet/Access.

Ngoài ra ta còn có thêm tùy chọn sử dụng ODBCDIRECT để truy cập dữ liệu Client/Server. Đây là một chuyển đổi để truy cập cơ sở dữ liệu server trực tiếp thông qua DAO mà không cần nạp bộ máy cơ sở dữ liệu Jet. Tùy chọn này thích hợp khi ta phải dùng DAO để truy cập dữ liệu Client/Server mà không cần bận tâm về tính linh hoạt, khả năng sử dụng lại và tính dễ bảo trì của chương trình.

Ví dụ: Tạo một Form có sử dụng ODBCDirect và DAO Data Control.

  • Tạo dự án mới.
  • Tham chiếu đến điều khiển lưới Microsoft Data Bound Grid Control trong mục Project\Components.
  • Tạo Form có dạng sau:

12Hình 10.4: Ví dụ về ODBC Direct

1: DBGrid. Name: dbGrid1.

2: Data Control. Name: Data1.

  • Đổi thuộc tính DefaultType của DataControl là 1 – Use ODBC. Điều này làm cho chương trình thực hiên nhanh hơn.
  • Thuộc tính Connect của Data1 là: ODBC;DSN=DBHH
  • Đặt thuộc tính Record Source của Data Control:

Select * From THANGHOA

Đặt thuộc tính Data Source của DBGrid1 là: Data1.

Lưu dự án và thực thi chương trình.

Truy cập dữ liệu dùng điều khiển dữ liệu từ xa

Điều khiển dữ liệu từ xa (Remote Data Control - RDC) là một cách khác truy cập dữ liệu từ xa trong các ứng dụng Visual Basic. Điều khiển này dùng một giao diện lập trình tương tự như điều khiển ADO Data hay DAO Data.

Ví dụ: Sử dụng RDC để hiển thị dữ liệu trên lưới:

  • Ở đây ta có sử dụng Remote Data Control và lưới hiển thị dữ liệu, do đó ta tham chiếu đến các thành phần này bằng cách chọn Project\Components…, thiết lập tham chiếu đến Microsoft Remote Data Control và Microsoft Data Bound Grid Control. Nhấp OK.
  • Thiết kế Form có dạng sau:

11Hình 10.5: Ví dụ về Remote Data Control

1: RemoteDataControl. Name: rdcHangHoa

2: DBGrid. Name: dbgHangHoa.

  • Đặt thuộc tính DataSourceName của điều khiển rdcHangHoa là DBHH (DSN đã tạo trước đây).
  • Định thuộc tính SQL của điều khiển rdcHangHoa là:

Select * From THANGHOA

  • Chỉ định thuộc tính DataSource của điều khiển dbgHangHoa là rdcHangHoa.
  • Thực thi chương trình.

Remote Data Object (RDO)

Đối tượng dữ liệu từ xa (Remote Data Objects - RDO) được mô tả dạng hình cây tương tự như DAO. Tuy nhiên mô hình đối tượng RDO đơn giản hơn DAO.

Dù vậy ta không thể dùng RDO để tạo đối tượng cơ sở dữ liệu như bảng, view, thủ tục chứa sẵn…

Để tham chiếu đến RDO ta vào Project\References…\Microsoft Remote Data Object 2.0.

Mô hình đối tượng RDO:

Đối tượng rdoengine

Đây là đối tượng ở cấp cao nhất trong mô hình RDO, giới thiệu về các thành phần của mô hình. Ta không cần phải khởi tạo đối tượng này cách tường minh bởi vì nó được khởi tạo tự động.

Questions & Answers

Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
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
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