mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-06 14:52:03 +01:00
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2484 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
89 lines
3.0 KiB
Plaintext
89 lines
3.0 KiB
Plaintext
[[Property:title|ADO.NET Sample]]
|
|
[[Property:weight|0]]
|
|
[[Property:uuid|45d24893-63d0-c2a9-9f62-ead08ca4b901]]
|
|
This sample consist of a command line showing how to interact with a database.
|
|
|
|
The DataReader object is somewhat synonymous with a read-only/forward-only cursor over data. The DataReader API supports flat as well as hierarchical data. A DataReader object is returned after executing a command against a database. The format of the returned DataReader object is different from a recordset. For example, you might use the DataReader to show the results of a search list in a web page.
|
|
|
|
==Compiling==
|
|
|
|
To compile the example:
|
|
# Launch EiffelStudio.
|
|
# Select '''Use existing Ace (control file)''' and click '''OK'''
|
|
# Browse to ''$ISE_EIFFEL\examples\dotnet\ado\ado3\''
|
|
# Choose the Ace file for the version of the .net framework you are running
|
|
# Choose the directory where the project will be compiled, by default the same directory containing the Ace file.
|
|
# Click '''OK'''.
|
|
|
|
|
|
==Running==
|
|
|
|
After you launch the sample, the following output appears:
|
|
<code>
|
|
Customer ID Company Name
|
|
ALFKI Alfreds Futterkiste
|
|
ANATR Ana Trujillo Emparedados y helados
|
|
ANTON Antonio Moreno Taquera
|
|
AROUT Around the Horn
|
|
BERGS Berglunds snabbkp
|
|
BLAUS Blauer See Delikatessen
|
|
BLONP Blondesddsl p`re et fils
|
|
BOLID Blido Comidas preparadas
|
|
BONAP Bon app'
|
|
BOTTM Bottom-Dollar Markets
|
|
BSBEV B's Beverages
|
|
CACTU Cactus Comidas para llevar
|
|
CENTC Centro comercial Moctezuma
|
|
CHOPS Chop-suey Chinese
|
|
COMMI Comrcio Mineiro
|
|
CONSH Consolidated Holdings
|
|
DRACD Drachenblut Delikatessen
|
|
DUMON Du monde entier
|
|
EASTC Eastern Connection
|
|
... ... ...
|
|
WILMK Wilman Kala
|
|
WOLZA Wolski Zajazd
|
|
</code>
|
|
|
|
When the display is finished, the application wait for you to pressed the return key to finish the application.
|
|
|
|
==Under the Hood==
|
|
|
|
This application shows how to interact with a database. First the connection to the database is opened:
|
|
<code>
|
|
create connection.make ("server=(local)\NetSDK;Trusted_Connection=yes;database=northwind")
|
|
</code>
|
|
Then a request to the database is made:
|
|
<code>
|
|
create command.make ("select * from customers", connection)
|
|
connection.open
|
|
reader := command.execute_reader
|
|
</code>
|
|
Finally, the result of the request is displayed:
|
|
<code>
|
|
from
|
|
ok := reader.read
|
|
until
|
|
not ok
|
|
loop
|
|
io.put_string (reader.item ("CustomerID").to_string)
|
|
io.put_string ("%T%T")
|
|
io.put_string (reader.item ("CompanyName").to_string)
|
|
io.new_line
|
|
ok := reader.read
|
|
end
|
|
</code>
|
|
|
|
This sample uses the following ADO.NET classes:
|
|
* <eiffel>SQL_DATA_READER</eiffel>
|
|
* <eiffel>SQL_CONNECTION</eiffel>
|
|
* <eiffel>SQL_COMMAND</eiffel>
|
|
|
|
==Notes==
|
|
|
|
This sample is translated from the example located in the QuickStart\howto\samples\adoplus subdirectory of the .NET Framework SDK samples directory of Microsoft Visual Studio .NET.
|
|
|
|
|
|
|
|
|